Skip to content

Commit 688c6f3

Browse files
committed
Deprecate calling ReflectionMethod::__construct() with 1 argument
1 parent beaf1e8 commit 688c6f3

10 files changed

+48
-13
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ PHP 8.4 UPGRADE NOTES
169169
. Calling pg_field_is_null() with 2 arguments is deprecated. Use the
170170
3-parameter signature with a null $row parameter instead.
171171

172+
- Reflection:
173+
. Calling ReflectionMethod::__construct() with 1 argument is deprecated.
174+
Use ReflectionMethod::createFromMethodName() instead.
175+
172176
========================================
173177
5. Changed Functions
174178
========================================

ext/reflection/php_reflection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,14 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
32043204
zend_function *mptr;
32053205

32063206
if (is_constructor) {
3207+
if (ZEND_NUM_ARGS() == 1) {
3208+
zend_error(E_DEPRECATED, "Calling ReflectionMethod::__construct() with 1 argument is deprecated, "
3209+
"use ReflectionMethod::createFromMethodName() instead");
3210+
if (UNEXPECTED(EG(exception))) {
3211+
RETURN_THROWS();
3212+
}
3213+
}
3214+
32073215
ZEND_PARSE_PARAMETERS_START(1, 2)
32083216
Z_PARAM_OBJ_OR_STR(arg1_obj, arg1_str)
32093217
Z_PARAM_OPTIONAL

ext/reflection/tests/008.phpt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,28 @@ foreach ($a as $key=>$val) {
3232

3333
echo "Done\n";
3434
?>
35-
--EXPECT--
35+
--EXPECTF--
36+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
3637
string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name"
3738
string(91) "ReflectionMethod::createFromMethodName(): Argument #1 ($method) must be a valid method name"
39+
40+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
3841
string(90) "ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name"
3942
string(91) "ReflectionMethod::createFromMethodName(): Argument #1 ($method) must be a valid method name"
43+
44+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
4045
string(23) "Class "" does not exist"
4146
string(23) "Class "" does not exist"
47+
48+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
4249
string(24) "Class "a" does not exist"
4350
string(24) "Class "a" does not exist"
51+
52+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
4453
string(23) "Class "" does not exist"
4554
string(23) "Class "" does not exist"
55+
56+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
4657
string(24) "Class "a" does not exist"
4758
string(24) "Class "a" does not exist"
4859
string(23) "Class "" does not exist"

ext/reflection/tests/ReflectionMethod_constructor_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class NewCtor {
1010

1111
}
1212
echo "New-style constructor:\n";
13-
$methodInfo = new ReflectionMethod("NewCtor::__construct");
13+
$methodInfo = new ReflectionMethod("NewCtor", "__construct");
1414
var_dump($methodInfo->isConstructor());
1515

1616
class ExtendsNewCtor extends NewCtor {

ext/reflection/tests/ReflectionMethod_constructor_error1.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ try {
6565
?>
6666
--EXPECTF--
6767
Wrong type of argument (bool):
68+
69+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
6870
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
6971
Stack trace:
7072
#0 %s ReflectionMethod->__construct('1')
7173
#1 {main}
7274
Wrong type of argument (int):
75+
76+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
7377
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
7478
Stack trace:
7579
#0 %s ReflectionMethod->__construct('3')
@@ -85,18 +89,26 @@ Stack trace:
8589
#0 %s ReflectionMethod->__construct('TestClass', '1')
8690
#1 {main}
8791
No method given:
92+
93+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
8894
ReflectionException: ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be a valid method name in %s:%d
8995
Stack trace:
9096
#0 %s ReflectionMethod->__construct('TestClass')
9197
#1 {main}
9298
Class and Method in same string, bad method name:
99+
100+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
93101
ReflectionException: Method TestClass::foop::dedoop() does not exist in %s:%d
94102
Stack trace:
95103
#0 %s ReflectionMethod->__construct('TestClass::foop...')
96104
#1 {main}
97105
Class and Method in same string, bad class name:
106+
107+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d
98108
ReflectionException: Class "TestCla" does not exist in %s:%d
99109
Stack trace:
100110
#0 %s ReflectionMethod->__construct('TestCla::foo')
101111
#1 {main}
102112
Class and Method in same string (ok):
113+
114+
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in %s on line %d

ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ reflectMethodModifiers("DerivedClass");
8787
reflectMethodModifiers("TestInterface");
8888
reflectMethodModifiers("AbstractClass");
8989

90-
$a = new ReflectionMethod('ReflectionMethod::getModifiers');
90+
$a = new ReflectionMethod('ReflectionMethod', 'getModifiers');
9191

9292
echo "ReflectionMethod::getModifiers() modifiers:\n";
9393
printf("0x%08x\n", $a->getModifiers());

ext/reflection/tests/ReflectionMethod_getStaticVariables_basic.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class TestClass {
2121
}
2222

2323
echo "Public method:\n";
24-
$methodInfo = new ReflectionMethod('TestClass::foo');
24+
$methodInfo = new ReflectionMethod('TestClass', 'foo');
2525
var_dump($methodInfo->getStaticVariables());
2626

2727
echo "\nPrivate method:\n";
28-
$methodInfo = new ReflectionMethod('TestClass::bar');
28+
$methodInfo = new ReflectionMethod('TestClass', 'bar');
2929
var_dump($methodInfo->getStaticVariables());
3030

3131
echo "\nMethod with no static variables:\n";
32-
$methodInfo = new ReflectionMethod('TestClass::noStatics');
32+
$methodInfo = new ReflectionMethod('TestClass', 'noStatics');
3333
var_dump($methodInfo->getStaticVariables());
3434

3535
echo "\nInternal Method:\n";
36-
$methodInfo = new ReflectionMethod('ReflectionClass::getName');
36+
$methodInfo = new ReflectionMethod('ReflectionClass', 'getName');
3737
var_dump($methodInfo->getStaticVariables());
3838

3939
?>

ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $testClassInstance->prop = "Hello";
3535

3636
$foo = new ReflectionMethod($testClassInstance, 'foo');
3737
$staticMethod = ReflectionMethod::createFromMethodName('TestClass::staticMethod');
38-
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
38+
$privateMethod = new ReflectionMethod("TestClass", "privateMethod");
3939

4040
echo "\nNon-instance:\n";
4141
try {
@@ -52,7 +52,7 @@ echo "\nPrivate method:\n";
5252
var_dump($privateMethod->invokeArgs($testClassInstance, array()));
5353

5454
echo "\nAbstract method:\n";
55-
$abstractMethod = new ReflectionMethod("AbstractClass::foo");
55+
$abstractMethod = new ReflectionMethod("AbstractClass", "foo");
5656
try {
5757
$abstractMethod->invokeArgs($testClassInstance, array());
5858
} catch (ReflectionException $e) {

ext/reflection/tests/ReflectionMethod_invoke_basic.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ abstract class AbstractClass {
4040

4141
$foo = new ReflectionMethod('TestClass', 'foo');
4242
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
43-
$staticMethod = new ReflectionMethod('TestClass::staticMethod');
44-
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
45-
$methodThatThrows = new ReflectionMethod("TestClass::willThrow");
43+
$staticMethod = new ReflectionMethod('TestClass', 'staticMethod');
44+
$privateMethod = new ReflectionMethod('TestClass', 'privateMethod');
45+
$methodThatThrows = new ReflectionMethod('TestClass', 'willThrow');
4646

4747
$testClassInstance = new TestClass();
4848
$testClassInstance->prop = "Hello";

tests/classes/autoload_014.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spl_autoload_register(function ($name) {
88
});
99

1010
try {
11-
new ReflectionMethod("UndefC::test");
11+
new ReflectionMethod("UndefC", "test");
1212
}
1313
catch (ReflectionException $e) {
1414
echo $e->getMessage();

0 commit comments

Comments
 (0)