mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-9905: constant() behaves inconsistent when class is undefined
Directly referring to a constant of an undefined throws an exception; there is not much point in `constant()` raising a fatal error in this case. Closes GH-9907.
This commit is contained in:
parent
e1c52d1a7c
commit
b2186ca7c4
4 changed files with 17 additions and 3 deletions
3
NEWS
3
NEWS
|
@ -2,6 +2,9 @@ PHP NEWS
|
||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? ??? ????, PHP 8.1.14
|
?? ??? ????, PHP 8.1.14
|
||||||
|
|
||||||
|
- Core:
|
||||||
|
. Fixed bug GH-9905 (constant() behaves inconsistent when class is undefined).
|
||||||
|
(cmb)
|
||||||
|
|
||||||
24 Nov 2022, PHP 8.1.13
|
24 Nov 2022, PHP 8.1.13
|
||||||
|
|
||||||
|
|
|
@ -589,7 +589,7 @@ PHP_FUNCTION(constant)
|
||||||
ZEND_PARSE_PARAMETERS_END();
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
scope = zend_get_executed_scope();
|
scope = zend_get_executed_scope();
|
||||||
c = zend_get_constant_ex(const_name, scope, 0);
|
c = zend_get_constant_ex(const_name, scope, ZEND_FETCH_CLASS_EXCEPTION);
|
||||||
if (!c) {
|
if (!c) {
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
12
ext/standard/tests/general_functions/gh9905.phpt
Normal file
12
ext/standard/tests/general_functions/gh9905.phpt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
--TEST--
|
||||||
|
GH-9905 (constant() behaves inconsistent when class is undefined)
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
try {
|
||||||
|
\constant("\NonExistantClass::non_existant_constant");
|
||||||
|
} catch (\Throwable|\Error|\Exception $e) {
|
||||||
|
echo($e->getMessage());
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Class "NonExistantClass" not found
|
|
@ -21,5 +21,4 @@ try {
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
define(): Argument #1 ($constant_name) cannot be a class constant
|
define(): Argument #1 ($constant_name) cannot be a class constant
|
||||||
|
Class "" not found
|
||||||
Fatal error: Class "" not found in %s on line %d
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue