In normal way, I know that we can call parent static method with ::
sign but it seems that in Yii2 Framework, we should call static components method via arrow sign (object operator).
I'd like to know how its possible?
For example, in
$foo->on(Foo::EVENT_HELLO, 'function_name');
on()
is an static method of yii\base\component
but we call it with arrow.
Component::on()
is not static:
public function on($name, $handler, $data = null, $append = true) { $this->ensureBehaviors(); if (strpos($name, '*') !== false) { if ($append || empty($this->_eventWildcards[$name])) { $this->_eventWildcards[$name][] = [$handler, $data]; } else { array_unshift($this->_eventWildcards[$name], [$handler, $data]); } return; } if ($append || empty($this->_events[$name])) { $this->_events[$name][] = [$handler, $data]; } else { array_unshift($this->_events[$name], [$handler, $data]); } }
Event::on()
is static:
public static function on($class, $name, $handler, $data = null, $append = true) { $class = ltrim($class, '\\'); if (strpos($class, '*') !== false || strpos($name, '*') !== false) { if ($append || empty(self::$_eventWildcards[$name][$class])) { self::$_eventWildcards[$name][$class][] = [$handler, $data]; } else { array_unshift(self::$_eventWildcards[$name][$class], [$handler, $data]); } return; } if ($append || empty(self::$_events[$name][$class])) { self::$_events[$name][$class][] = [$handler, $data]; } else { array_unshift(self::$_events[$name][$class], [$handler, $data]); } }
But I've never seen that someone is using it in non-static way.