diff --git a/NEWS b/NEWS index 28f3de0653b..0022c958e90 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.1.14 +- Core: + . Fixed bug GH-9905 (constant() behaves inconsistent when class is undefined). + (cmb) 24 Nov 2022, PHP 8.1.13 diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 23f736d2009..1e50a37f2c6 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -589,7 +589,7 @@ PHP_FUNCTION(constant) ZEND_PARSE_PARAMETERS_END(); 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) { RETURN_THROWS(); } diff --git a/ext/standard/tests/general_functions/gh9905.phpt b/ext/standard/tests/general_functions/gh9905.phpt new file mode 100644 index 00000000000..33d2f4f7370 --- /dev/null +++ b/ext/standard/tests/general_functions/gh9905.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-9905 (constant() behaves inconsistent when class is undefined) +--FILE-- +getMessage()); +} +?> +--EXPECT-- +Class "NonExistantClass" not found diff --git a/tests/lang/bug44827.phpt b/tests/lang/bug44827.phpt index 9220439c884..997a1a633f8 100644 --- a/tests/lang/bug44827.phpt +++ b/tests/lang/bug44827.phpt @@ -21,5 +21,4 @@ try { ?> --EXPECTF-- define(): Argument #1 ($constant_name) cannot be a class constant - -Fatal error: Class "" not found in %s on line %d +Class "" not found