Skip to content

Commit 4b1feda

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-9905: constant() behaves inconsistent when class is undefined
2 parents 6bd8f40 + b2186ca commit 4b1feda

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.1
44

5+
- Core:
6+
. Fixed bug GH-9905 (constant() behaves inconsistent when class is undefined).
7+
(cmb)
8+
59
27 Nov 2022, PHP 8.2.0
610

711
- CLI:

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ PHP_FUNCTION(constant)
525525
ZEND_PARSE_PARAMETERS_END();
526526

527527
scope = zend_get_executed_scope();
528-
c = zend_get_constant_ex(const_name, scope, 0);
528+
c = zend_get_constant_ex(const_name, scope, ZEND_FETCH_CLASS_EXCEPTION);
529529
if (!c) {
530530
RETURN_THROWS();
531531
}
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)