Re: BC break: ReflectionMethod::invoke() expects parameter1to be object, string given
| From: | Rowan Collins | Date: | Tue, 23 Aug 2016 13:37:26 +0000 |
| Subject: | Re: BC break: ReflectionMethod::invoke() expects parameter1to be object, string given | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95410@lists.php.net to get a copy of this message | ||
On 23/08/2016 14:20, Alexander Lisachenko wrote:
2016-08-23 16:13 GMT+03:00 Julien Pauli <jpauli@php.net
<mailto:jpauli@php.net>>:
No, How can this be ? B extends A , not A extends B ...
In this case, B'sfoo() will be called , which is the equivalent to
having a reflectionMethod from B , so useless to me.
Ok, how can I invoke Parent::whoami() with reflection and get exactly
"Child" as an output?
I've no idea why you'd want to, but note that using get_class($this), you can actually get that for a non-static method: https://3v4l.org/Rc7Dk
class MyParent {
public function whoami() {
echo get_class($this);
}
}
class MyChild extends MyParent {
public function whoami() {
echo "Don't call me now!";
parent::whoami();
}
}
$m = new reflectionMethod('MyParent', 'whoami');
$m->invoke(new MyChild);
So there is a gap in functionality between static and non-static methods here. I'm not sure reinterpreting a parameter which has always been ignored is the best way to solve it though.
Regards,
--
Rowan Collins
[IMSoP]