Re: BC break: ReflectionMethod::invoke() expects parameter1to be object, string given
| From: | Lauri Kenttä | Date: | Tue, 23 Aug 2016 15:05:29 +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-95417@lists.php.net to get a copy of this message | ||
On 2016-08-23 16:20, Alexander Lisachenko wrote:
Ok, how can I invoke Parent::whoami() with reflection and get exactly "Child" as an output? class Parent {Could you do it without reflection, then? I don't think so. Thus, I think your "use case" is broken by design. If you need to call Parent::whoami with the Child scope, maybe you shouldn't override the method in Child class at all. If this kind of functionality is generally needed, maybe it could be borrowed from C++: obj_b->A::whoami(); Translated to PHP/Reflection: new ReflectionMethod("B", "A::whoami")->invoke(); -- Lauri Kenttäpublic static function whoami() { echo static::class; }} class Child extends Parent {public static function whoami() { echo "Don't call me now!'; parent::whoami(); }}