yii\db\BaseActiveRecord::canGetProperty PHP Method

canGetProperty() public method

public canGetProperty ( $name, $checkVars = true, $checkBehaviors = true )
    public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
    {
        if (parent::canGetProperty($name, $checkVars, $checkBehaviors)) {
            return true;
        }
        try {
            return $this->hasAttribute($name);
        } catch (\Exception $e) {
            // `hasAttribute()` may fail on base/abstract classes in case automatic attribute list fetching used
            return false;
        }
    }

Usage Example

 public function __set($name, $value)
 {
     if ($this->_relation->canGetProperty($name)) {
         $this->_relation->{$name} = $value;
     } else {
         parent::__set($name, $value);
     }
 }