mirror of
https://github.com/php/php-src.git
synced 2026-03-26 17:22:15 +01:00
We don't want ReflectionMethod::invoke() to simply ignore its first argument, if the method to invoke is a static method. Instead we match its ZPP with that of ReflectionMethod::invokeArgs(). Furthermore, we apply the DRY principle by factoring out the code to a common helper function to prevent inadvertent future divergence of the implementations of both methods. As can be seen from the necessity to adapt some test cases, this causes a BC break for some pathological cases. Therefore we apply this patch to PHP 7.1 only, which is still in beta phase.
44 lines
856 B
PHP
44 lines
856 B
PHP
--TEST--
|
|
ReflectionMethod::invoke() with non object or null value
|
|
--FILE--
|
|
<?php
|
|
|
|
class a {
|
|
function a(){
|
|
}
|
|
}
|
|
class b {
|
|
}
|
|
|
|
$b = new b();
|
|
|
|
$a=new ReflectionClass("a");
|
|
$m=$a->getMethod("a");
|
|
|
|
try {
|
|
$m->invoke(null);
|
|
} catch (ReflectionException $E) {
|
|
echo $E->getMessage()."\n";
|
|
}
|
|
|
|
|
|
try {
|
|
$m->invoke($b);
|
|
} catch (ReflectionException $E) {
|
|
echo $E->getMessage()."\n";
|
|
}
|
|
|
|
$b = new a();
|
|
try {
|
|
$m->invoke($b);
|
|
} catch (ReflectionException $E) {
|
|
echo $E->getMessage()."\n";
|
|
}
|
|
|
|
echo "===DONE===\n";?>
|
|
--EXPECTF--
|
|
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in %s on line %d
|
|
Trying to invoke non static method a::a() without an object
|
|
Given object is not an instance of the class this method was declared in
|
|
===DONE===
|