Suppose following situation. There are class hierarchy, that uses various arguments list in a method, that might be extended for each descendant class.
<?php
header('Content-Type: text/plain; charset=utf-8');
class A {
public function __invoke(){
$arguments = implode(', ', func_get_args());
echo __METHOD__, ' arguments: ', $arguments, PHP_EOL;
}
}
class B extends A {
public function __invoke(){
// ... some actions ...
// call to parent method with current argument list
// ... some actions ...
}
}
?>
If this class hierarhy were implemented with fixed arguments of __invoke()
method, then I might use something like parent::__invoke($a, $b, $c, $etc);
to achieve my purpose. But, unfortunately both classes A
and B
has some functionality, that relies on various argument lists.
Now, the question: How can I call parent::__invoke()
from B::__invoke()
and pass it's arguments list?
And, yeah, I'll make it more complex: I can not rely on actual name of parent class, because chain might be extended further.
P.S.: I just want to mention this somewhere, because this thing is nearly saved my life today.