diff --git a/UPGRADING b/UPGRADING index 03c67ff9ea8..87dac6d3112 100644 --- a/UPGRADING +++ b/UPGRADING @@ -169,6 +169,10 @@ PHP 8.4 UPGRADE NOTES . Calling pg_field_is_null() with 2 arguments is deprecated. Use the 3-parameter signature with a null $row parameter instead. +- Reflection: + . Calling ReflectionMethod::__construct() with 1 argument is deprecated. + Use ReflectionMethod::createFromMethodName() instead. + ======================================== 5. Changed Functions ======================================== diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a725573aa90..53e978604ad 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3204,6 +3204,14 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_ zend_function *mptr; if (is_constructor) { + if (ZEND_NUM_ARGS() == 1) { + zend_error(E_DEPRECATED, "Calling ReflectionMethod::__construct() with 1 argument is deprecated, " + "use ReflectionMethod::createFromMethodName() instead"); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } + } + ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_OBJ_OR_STR(arg1_obj, arg1_str) Z_PARAM_OPTIONAL diff --git a/ext/reflection/tests/008.phpt b/ext/reflection/tests/008.phpt index 91227be7dd3..64866bbe699 100644 --- a/ext/reflection/tests/008.phpt +++ b/ext/reflection/tests/008.phpt @@ -32,17 +32,28 @@ foreach ($a as $key=>$val) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name" string(91) "ReflectionMethod::createFromMethodName(): Argument #1 ($method) must be a valid method name" + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name" string(91) "ReflectionMethod::createFromMethodName(): Argument #1 ($method) must be a valid method name" + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(23) "Class "" does not exist" string(23) "Class "" does not exist" + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(24) "Class "a" does not exist" string(24) "Class "a" does not exist" + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(23) "Class "" does not exist" string(23) "Class "" does not exist" + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d string(24) "Class "a" does not exist" string(24) "Class "a" does not exist" string(23) "Class "" does not exist" diff --git a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt index 5aa9909858c..3d26d682a56 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt @@ -10,7 +10,7 @@ class NewCtor { } echo "New-style constructor:\n"; -$methodInfo = new ReflectionMethod("NewCtor::__construct"); +$methodInfo = new ReflectionMethod("NewCtor", "__construct"); var_dump($methodInfo->isConstructor()); class ExtendsNewCtor extends NewCtor { diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt index 8c5bd7139ce..9a1e340d83a 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt @@ -65,11 +65,15 @@ try { ?> --EXPECTF-- Wrong type of argument (bool): + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d Stack trace: #0 %s ReflectionMethod->__construct('1') #1 {main} Wrong type of argument (int): + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d Stack trace: #0 %s ReflectionMethod->__construct('3') @@ -85,18 +89,26 @@ Stack trace: #0 %s ReflectionMethod->__construct('TestClass', '1') #1 {main} No method given: + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d Stack trace: #0 %s ReflectionMethod->__construct('TestClass') #1 {main} Class and Method in same string, bad method name: + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d ReflectionException: Method TestClass::foop::dedoop() does not exist in %s:%d Stack trace: #0 %s ReflectionMethod->__construct('TestClass::foop...') #1 {main} Class and Method in same string, bad class name: + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d ReflectionException: Class "TestCla" does not exist in %s:%d Stack trace: #0 %s ReflectionMethod->__construct('TestCla::foo') #1 {main} Class and Method in same string (ok): + +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index c5fe6aa41a2..e66ec739379 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -87,7 +87,7 @@ reflectMethodModifiers("DerivedClass"); reflectMethodModifiers("TestInterface"); reflectMethodModifiers("AbstractClass"); -$a = new ReflectionMethod('ReflectionMethod::getModifiers'); +$a = new ReflectionMethod('ReflectionMethod', 'getModifiers'); echo "ReflectionMethod::getModifiers() modifiers:\n"; printf("0x%08x\n", $a->getModifiers()); diff --git a/ext/reflection/tests/ReflectionMethod_getStaticVariables_basic.phpt b/ext/reflection/tests/ReflectionMethod_getStaticVariables_basic.phpt index 4c50b96b9d8..91b933058f1 100644 --- a/ext/reflection/tests/ReflectionMethod_getStaticVariables_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getStaticVariables_basic.phpt @@ -21,19 +21,19 @@ class TestClass { } echo "Public method:\n"; -$methodInfo = new ReflectionMethod('TestClass::foo'); +$methodInfo = new ReflectionMethod('TestClass', 'foo'); var_dump($methodInfo->getStaticVariables()); echo "\nPrivate method:\n"; -$methodInfo = new ReflectionMethod('TestClass::bar'); +$methodInfo = new ReflectionMethod('TestClass', 'bar'); var_dump($methodInfo->getStaticVariables()); echo "\nMethod with no static variables:\n"; -$methodInfo = new ReflectionMethod('TestClass::noStatics'); +$methodInfo = new ReflectionMethod('TestClass', 'noStatics'); var_dump($methodInfo->getStaticVariables()); echo "\nInternal Method:\n"; -$methodInfo = new ReflectionMethod('ReflectionClass::getName'); +$methodInfo = new ReflectionMethod('ReflectionClass', 'getName'); var_dump($methodInfo->getStaticVariables()); ?> diff --git a/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt b/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt index b4a4002e307..124f728052e 100644 --- a/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt +++ b/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt @@ -35,7 +35,7 @@ $testClassInstance->prop = "Hello"; $foo = new ReflectionMethod($testClassInstance, 'foo'); $staticMethod = ReflectionMethod::createFromMethodName('TestClass::staticMethod'); -$privateMethod = new ReflectionMethod("TestClass::privateMethod"); +$privateMethod = new ReflectionMethod("TestClass", "privateMethod"); echo "\nNon-instance:\n"; try { @@ -52,7 +52,7 @@ echo "\nPrivate method:\n"; var_dump($privateMethod->invokeArgs($testClassInstance, array())); echo "\nAbstract method:\n"; -$abstractMethod = new ReflectionMethod("AbstractClass::foo"); +$abstractMethod = new ReflectionMethod("AbstractClass", "foo"); try { $abstractMethod->invokeArgs($testClassInstance, array()); } catch (ReflectionException $e) { diff --git a/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt b/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt index 67b37411b42..66f3c50da02 100644 --- a/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt @@ -40,9 +40,9 @@ abstract class AbstractClass { $foo = new ReflectionMethod('TestClass', 'foo'); $methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs'); -$staticMethod = new ReflectionMethod('TestClass::staticMethod'); -$privateMethod = new ReflectionMethod("TestClass::privateMethod"); -$methodThatThrows = new ReflectionMethod("TestClass::willThrow"); +$staticMethod = new ReflectionMethod('TestClass', 'staticMethod'); +$privateMethod = new ReflectionMethod('TestClass', 'privateMethod'); +$methodThatThrows = new ReflectionMethod('TestClass', 'willThrow'); $testClassInstance = new TestClass(); $testClassInstance->prop = "Hello"; diff --git a/tests/classes/autoload_014.phpt b/tests/classes/autoload_014.phpt index 13f16f82640..eaba7f05c12 100644 --- a/tests/classes/autoload_014.phpt +++ b/tests/classes/autoload_014.phpt @@ -8,7 +8,7 @@ spl_autoload_register(function ($name) { }); try { - new ReflectionMethod("UndefC::test"); + new ReflectionMethod("UndefC", "test"); } catch (ReflectionException $e) { echo $e->getMessage();