Skip to content

Commit 75f3722

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-9905: constant() behaves inconsistent when class is undefined
2 parents cda97e7 + 4b1feda commit 75f3722

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ PHP_FUNCTION(constant)
519519
ZEND_PARSE_PARAMETERS_END();
520520

521521
scope = zend_get_executed_scope();
522-
c = zend_get_constant_ex(const_name, scope, 0);
522+
c = zend_get_constant_ex(const_name, scope, ZEND_FETCH_CLASS_EXCEPTION);
523523
if (!c) {
524524
RETURN_THROWS();
525525
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-9905 (constant() behaves inconsistent when class is undefined)
3+
--FILE--
4+
<?php
5+
try {
6+
\constant("\NonExistantClass::non_existant_constant");
7+
} catch (\Throwable|\Error|\Exception $e) {
8+
echo($e->getMessage());
9+
}
10+
?>
11+
--EXPECT--
12+
Class "NonExistantClass" not found

tests/lang/bug44827.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ try {
2121
?>
2222
--EXPECTF--
2323
define(): Argument #1 ($constant_name) cannot be a class constant
24-
25-
Fatal error: Class "" not found in %s on line %d
24+
Class "" not found

0 commit comments

Comments
 (0)