Skip to content

Commit 96ac2c4

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Lazy objects: Update class constants earlier
2 parents 8143eca + 64081d1 commit 96ac2c4

File tree

4 files changed

+31
-65
lines changed

4 files changed

+31
-65
lines changed

Zend/tests/lazy_objects/init_ast_const.phpt

Lines changed: 0 additions & 27 deletions
This file was deleted.

Zend/tests/lazy_objects/init_ast_const_failure.phpt

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
oss-fuzz #71407
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $x=x;
8+
}
9+
10+
$reflector = new ReflectionClass(C::class);
11+
12+
try {
13+
$obj = $reflector->newLazyGhost(function() {});
14+
clone $obj;
15+
} catch (Error $e) {
16+
printf("%s: %s\n", $e::class, $e->getMessage());
17+
}
18+
19+
20+
?>
21+
--EXPECT--
22+
Error: Undefined constant "x"

Zend/zend_lazy_objects.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
259259
return NULL;
260260
}
261261

262+
if (UNEXPECTED(!(reflection_ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
263+
if (UNEXPECTED(zend_update_class_constants(reflection_ce) != SUCCESS)) {
264+
ZEND_ASSERT(EG(exception));
265+
return NULL;
266+
}
267+
}
268+
262269
obj = zend_objects_new(reflection_ce);
263270

264271
for (int i = 0; i < obj->ce->default_properties_count; i++) {
@@ -373,12 +380,7 @@ ZEND_API zend_object *zend_lazy_object_mark_as_initialized(zend_object *obj)
373380

374381
zend_class_entry *ce = obj->ce;
375382

376-
if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
377-
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
378-
ZEND_ASSERT(EG(exception));
379-
return NULL;
380-
}
381-
}
383+
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED);
382384

383385
zval *default_properties_table = CE_DEFAULT_PROPERTIES_TABLE(ce);
384386
zval *properties_table = obj->properties_table;
@@ -568,12 +570,7 @@ ZEND_API zend_object *zend_lazy_object_init(zend_object *obj)
568570

569571
zend_class_entry *ce = obj->ce;
570572

571-
if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
572-
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
573-
ZEND_ASSERT(EG(exception));
574-
return NULL;
575-
}
576-
}
573+
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED);
577574

578575
if (zend_object_is_lazy_proxy(obj)) {
579576
return zend_lazy_object_init_proxy(obj);

0 commit comments

Comments
 (0)