yii\base\Component::__set PHP Метод

__set() публичный Метод

This method will check in the following order and act accordingly: - a property defined by a setter: set the property value - an event in the format of "on xyz": attach the handler to the event "xyz" - a behavior in the format of "as xyz": attach the behavior named as "xyz" - a property of a behavior: set the behavior property value Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.
См. также: __get()
public __set ( string $name, mixed $value )
$name string the property name or the event name
$value mixed the property value
    public function __set($name, $value)
    {
        $setter = 'set' . $name;
        if (method_exists($this, $setter)) {
            // set property
            $this->{$setter}($value);
            return;
        } elseif (strncmp($name, 'on ', 3) === 0) {
            // on event: attach event handler
            $this->on(trim(substr($name, 3)), $value);
            return;
        } elseif (strncmp($name, 'as ', 3) === 0) {
            // as behavior: attach behavior
            $name = trim(substr($name, 3));
            $this->attachBehavior($name, $value instanceof Behavior ? $value : Yii::createObject($value));
            return;
        } else {
            // behavior property
            $this->ensureBehaviors();
            foreach ($this->_behaviors as $behavior) {
                if ($behavior->canSetProperty($name)) {
                    $behavior->{$name} = $value;
                    return;
                }
            }
        }
        if (method_exists($this, 'get' . $name)) {
            throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
        } else {
            throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
        }
    }

Usage Example

Пример #1
0
 public function __set($name, $value)
 {
     if (is_int($name)) {
         $this->{$this->_containerName}[$name] = $value;
     } else {
         parent::__set($name, $value);
     }
 }
All Usage Examples Of yii\base\Component::__set