jclaveau / php-deferred-callchain

Simple fluent API that can be applied on instances or native variables asynchronously
MIT License
1 stars 0 forks source link

Support calls of static methods #9

Closed jclaveau closed 5 years ago

jclaveau commented 5 years ago

This case can be useful for singletons for example with Class::getInstance()...

jclaveau commented 5 years ago

Even if, since PHP 7 the syntax php $getMaxAge = (new DeferredCallChain)->setName('plop')::getMaxAge(); would throw a PHP Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), accessing $this during __callStatic produces produces an error.

Even exploiting debug_backtrace do not provide access to the instance on which the static method is called (until now at least).

jclaveau commented 5 years ago

The only solution I found which works (even for php 5) is to first call the function on the instance then on the class as a static method