yii\base\Component::hasMethod PHP Method

hasMethod() public method

A method is defined if: - the class has a method with the specified name - an attached behavior has a method with the given name (when $checkBehaviors is true).
public hasMethod ( string $name, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkBehaviors boolean whether to treat behaviors' methods as methods of this component
return boolean whether the property is defined
    public function hasMethod($name, $checkBehaviors = true)
    {
        if (method_exists($this, $name)) {
            return true;
        } elseif ($checkBehaviors) {
            $this->ensureBehaviors();
            foreach ($this->_behaviors as $behavior) {
                if ($behavior->hasMethod($name)) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 public function hasMethod($name, $checkBehaviors = true)
 {
     if (method_exists($this->obj, $name)) {
         return true;
     }
     return parent::hasMethod($name, $checkBehaviors);
 }