Skip to content

Commit b963249

Browse files
committed
Fixed bug #65291 - get_defined_constants() crash with __CLASS__ in trait
Also fix and test for get_defined_constants(true)
1 parent a015fa8 commit b963249

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Zend/tests/bug65291.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Tester
1717

1818
$foo = Tester::testStaticFunction();
1919
get_defined_constants();
20+
get_defined_constants(true);
2021

2122
echo $foo;
2223
?>

Zend/zend_builtin_functions.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,11 +1998,16 @@ ZEND_FUNCTION(get_defined_constants)
19981998
while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &val, &pos) != FAILURE) {
19991999
zval *const_val;
20002000

2001+
if (!val->name) {
2002+
/* skip special constants */
2003+
goto next_constant;
2004+
}
2005+
20012006
if (val->module_number == PHP_USER_CONSTANT) {
20022007
module_number = i;
20032008
} else if (val->module_number > i || val->module_number < 0) {
20042009
/* should not happen */
2005-
goto bad_module_id;
2010+
goto next_constant;
20062011
} else {
20072012
module_number = val->module_number;
20082013
}
@@ -2019,7 +2024,7 @@ ZEND_FUNCTION(get_defined_constants)
20192024
INIT_PZVAL(const_val);
20202025

20212026
add_assoc_zval_ex(modules[module_number], val->name, val->name_len, const_val);
2022-
bad_module_id:
2027+
next_constant:
20232028
zend_hash_move_forward_ex(EG(zend_constants), &pos);
20242029
}
20252030
efree(module_names);

0 commit comments

Comments
 (0)