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

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

A property can be read if: - the class has a getter method associated with the specified name (in this case, property name is case-insensitive); - the class has a member variable with the specified name (when $checkVars is true); - an attached behavior has a readable property of the given name (when $checkBehaviors is true).
См. также: canSetProperty()
public canGetProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkVars boolean whether to treat member variables as properties
$checkBehaviors boolean whether to treat behaviors' properties as properties of this component
Результат boolean whether the property can be read
    public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
    {
        if (method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name)) {
            return true;
        } elseif ($checkBehaviors) {
            $this->ensureBehaviors();
            foreach ($this->_behaviors as $behavior) {
                if ($behavior->canGetProperty($name, $checkVars)) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * @inheritdoc
  */
 public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
 {
     if (property_exists($this->obj, $name)) {
         return true;
     }
     return parent::canGetProperty($name, $checkVars, $checkBehaviors);
 }