mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
[RFC] Deprecate ReflectionClass::getConstant() for missing constants (#19456)
https://wiki.php.net/rfc/deprecations_php_8_5
This commit is contained in:
parent
a68f3d6374
commit
ffdc1044c9
6 changed files with 44 additions and 5 deletions
|
@ -4855,6 +4855,11 @@ ZEND_METHOD(ReflectionClass, getConstant)
|
|||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
if ((c = zend_hash_find_ptr(constants_table, name)) == NULL) {
|
||||
zend_error(
|
||||
E_DEPRECATED,
|
||||
"ReflectionClass::getConstant() for a non-existent constant is deprecated, "
|
||||
"use ReflectionClass::hasConstant() to check if the constant exists"
|
||||
);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
ZVAL_COPY_OR_DUP(return_value, &c->value);
|
||||
|
|
|
@ -9,6 +9,8 @@ $class = new ReflectionClass("Foo");
|
|||
var_dump($class->getConstant("c1"));
|
||||
var_dump($class->getConstant("c2"));
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
int(1)
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -23,19 +23,31 @@ foreach($classes as $class) {
|
|||
var_dump($rc->getConstant('doesnotexist'));
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Reflecting on class C:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on class D:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on class E:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on class F:
|
||||
string(12) "hello from F"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on class X:
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -12,8 +12,14 @@ var_dump($rc->getConstant(1));
|
|||
var_dump($rc->getConstant(1.5));
|
||||
var_dump($rc->getConstant(true));
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Check invalid params:
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -23,19 +23,31 @@ foreach($classes as $class) {
|
|||
var_dump($rc->getConstant('doesNotexist'));
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Reflecting on instance of class C:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on instance of class D:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on instance of class E:
|
||||
string(12) "hello from C"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on instance of class F:
|
||||
string(12) "hello from F"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Reflecting on instance of class X:
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -20,9 +20,11 @@ var_dump($foo->getConstant("no such const"));
|
|||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
int(10)
|
||||
string(0) ""
|
||||
string(4) "test"
|
||||
|
||||
Deprecated: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue