mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Deprecate calling ReflectionMethod::__construct() with 1 argument
This commit is contained in:
@@ -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
|
||||
========================================
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
?>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -8,7 +8,7 @@ spl_autoload_register(function ($name) {
|
||||
});
|
||||
|
||||
try {
|
||||
new ReflectionMethod("UndefC::test");
|
||||
new ReflectionMethod("UndefC", "test");
|
||||
}
|
||||
catch (ReflectionException $e) {
|
||||
echo $e->getMessage();
|
||||
|
||||
Reference in New Issue
Block a user