mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
[RFC] Deprecate ReflectionClass::getConstant() for missing constants (#19456)
https://wiki.php.net/rfc/deprecations_php_8_5
This commit is contained in:
@@ -4855,6 +4855,11 @@ ZEND_METHOD(ReflectionClass, getConstant)
|
|||||||
}
|
}
|
||||||
} ZEND_HASH_FOREACH_END();
|
} ZEND_HASH_FOREACH_END();
|
||||||
if ((c = zend_hash_find_ptr(constants_table, name)) == NULL) {
|
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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
ZVAL_COPY_OR_DUP(return_value, &c->value);
|
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("c1"));
|
||||||
var_dump($class->getConstant("c2"));
|
var_dump($class->getConstant("c2"));
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
int(1)
|
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)
|
bool(false)
|
||||||
|
|||||||
@@ -23,19 +23,31 @@ foreach($classes as $class) {
|
|||||||
var_dump($rc->getConstant('doesnotexist'));
|
var_dump($rc->getConstant('doesnotexist'));
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
Reflecting on class C:
|
Reflecting on class C:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on class D:
|
Reflecting on class D:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on class E:
|
Reflecting on class E:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on class F:
|
Reflecting on class F:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on class X:
|
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)
|
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)
|
bool(false)
|
||||||
|
|||||||
@@ -12,8 +12,14 @@ var_dump($rc->getConstant(1));
|
|||||||
var_dump($rc->getConstant(1.5));
|
var_dump($rc->getConstant(1.5));
|
||||||
var_dump($rc->getConstant(true));
|
var_dump($rc->getConstant(true));
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
Check invalid params:
|
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)
|
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)
|
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)
|
bool(false)
|
||||||
|
|||||||
@@ -23,19 +23,31 @@ foreach($classes as $class) {
|
|||||||
var_dump($rc->getConstant('doesNotexist'));
|
var_dump($rc->getConstant('doesNotexist'));
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
Reflecting on instance of class C:
|
Reflecting on instance of class C:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on instance of class D:
|
Reflecting on instance of class D:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on instance of class E:
|
Reflecting on instance of class E:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on instance of class F:
|
Reflecting on instance of class F:
|
||||||
string(12) "hello from 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)
|
bool(false)
|
||||||
Reflecting on instance of class X:
|
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)
|
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)
|
bool(false)
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ var_dump($foo->getConstant("no such const"));
|
|||||||
|
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
int(10)
|
int(10)
|
||||||
string(0) ""
|
string(0) ""
|
||||||
string(4) "test"
|
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)
|
bool(false)
|
||||||
Done
|
Done
|
||||||
|
|||||||
Reference in New Issue
Block a user