diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index b3b643cec7e..f65a71a7266 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -519,7 +519,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