Re: BC break: ReflectionMethod::invoke() expects parameter 1 to be object, string given

From: Date: Mon, 22 Aug 2016 14:38:36 +0000
Subject: Re: BC break: ReflectionMethod::invoke() expects parameter 1 to be object, string given
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-95378@lists.php.net to get a copy of this message
On 22/08/2016 12:17, Nicolas Grekas wrote:
in ReflectionMethod::invoke(): the method doesn't accept a string as first argument anymore, see e.g.: https://3v4l.org/pImmv
To be precise, in prior versions, the first argument was completely ignored for static methods: https://3v4l.org/8o4Hm $m->invoke('some_other_class_name', 'baz'); // Warns in 7.1.0beta3, ignores everywhere else $m->invoke(42, 'baz'); // Warns in 7.1.0beta3, ignores everywhere else $m->invoke(new DateTime, 'baz'); // OK in all versions $m->invoke($m, 'baz'); // OK in all versions It is still ignored if it is a valid object, so the current beta's behaviour doesn't actually make a lot of sense. The most logical would be for it to fail on any value other than null, since for a non-static method any other object will give "Given object is not an instance of the class this method was declared in" (except in HHVM, which just invokes on whatever object you give it): https://3v4l.org/sCFcA However, simply documenting that "the first argument is ignored for static methods", and removing the parameter validation, would probably be sensible for BC if there is likely to be real-world code passing something other than null. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#95378) next »