This problem exists with anonymous functions that work the same way. You have several ways to get around:
1) modify your __call to check if it is a method, if not, call the property:
if (property_exists($this, $name) && is_object($this->$name) && method_exists($this->$name, "__invoke")) { call_user_func_array($this->name, $args); }
2) call __invoke directly: $c->worker->__invoke();
3) Save the property to a temporary variable:
$tempVar = $c->worker; $tempVar();
4) (almost the same as 3) (source: http://marc.info/?l=php-internals&m=136336319809565&w=4 )
${'_'.!$_=$c->worker}();
5) Use call_user_func or call_user_func_array :
call_user_func($c->worker);
bwoebi
source share