PHP callbacks are not like callbacks in most other languages. Typical languages โโare callbacks as pointers, while PHP represents them as strings. There is no โmagicโ between the string or array() syntax and the call. call_user_func(array($obj, 'str')) syntactically the same as $obj->str() . If str is private, the call will fail.
You just have to make your event handler public. This has real semantic meaning, i.e. "Designed to be called from outside my class."
This implementation has other interesting side effects, for example:
class Food { static function getCallback() { return 'self::func'; } static function func() {} static function go() { call_user_func(self::getCallback());
zildjohn01
source share