File tree 2 files changed +42
-2
lines changed
2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-15823: Wrong expectations in zend_lazy_object_get_properties()
3
+ --FILE--
4
+ <?php
5
+
6
+ class C {
7
+ public int $ a = 1 ;
8
+ }
9
+
10
+ $ reflector = new ReflectionClass (C::class);
11
+ $ calls = 0 ;
12
+ $ obj = $ reflector ->newLazyGhost (function ($ obj ) use (&$ calls ) {
13
+ if ($ calls ++ === 0 ) {
14
+ throw new Error ("initializer " );
15
+ }
16
+ $ obj ->a = 2 ;
17
+ });
18
+
19
+ // Builds properties ht without lazy initialization
20
+ var_dump ($ obj );
21
+ try {
22
+ // Lazy initialization fails during fetching of properties ht
23
+ json_encode ($ obj );
24
+ } catch (Error $ e ) {
25
+ printf ("%s: %s \n" , $ e ::class, $ e ->getMessage ());
26
+ }
27
+
28
+ var_dump (json_encode ($ obj ));
29
+
30
+ ?>
31
+ --EXPECTF--
32
+ lazy ghost object(C)#%d (0) {
33
+ ["a"]=>
34
+ uninitialized(int)
35
+ }
36
+ Error: initializer
37
+ string(7) "{"a":2}"
Original file line number Diff line number Diff line change @@ -624,8 +624,11 @@ ZEND_API HashTable *zend_lazy_object_get_properties(zend_object *object)
624
624
625
625
zend_object * tmp = zend_lazy_object_init (object );
626
626
if (UNEXPECTED (!tmp )) {
627
- ZEND_ASSERT (!object -> properties || object -> properties == & zend_empty_array );
628
- return object -> properties = (zend_array * ) & zend_empty_array ;
627
+ if (!object -> properties ) {
628
+ /* Callers expect object->properties to be set */
629
+ object -> properties = (zend_array * ) & zend_empty_array ;
630
+ }
631
+ return (zend_array * ) & zend_empty_array ;
629
632
}
630
633
631
634
object = tmp ;
You can’t perform that action at this time.
0 commit comments