Coverage Report

Created: 2026-06-02 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/Zend/zend_object_handlers.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Zend Engine                                                          |
4
   +----------------------------------------------------------------------+
5
   | Copyright © Zend Technologies Ltd., a subsidiary company of          |
6
   |     Perforce Software, Inc., and Contributors.                       |
7
   +----------------------------------------------------------------------+
8
   | This source file is subject to the Modified BSD License that is      |
9
   | bundled with this package in the file LICENSE, and is available      |
10
   | through the World Wide Web at <https://www.php.net/license/>.        |
11
   |                                                                      |
12
   | SPDX-License-Identifier: BSD-3-Clause                                |
13
   +----------------------------------------------------------------------+
14
   | Authors: Andi Gutmans <andi@php.net>                                 |
15
   |          Zeev Suraski <zeev@php.net>                                 |
16
   |          Dmitry Stogov <dmitry@php.net>                              |
17
   +----------------------------------------------------------------------+
18
*/
19
20
#include "zend.h"
21
#include "zend_globals.h"
22
#include "zend_lazy_objects.h"
23
#include "zend_variables.h"
24
#include "zend_API.h"
25
#include "zend_objects.h"
26
#include "zend_objects_API.h"
27
#include "zend_object_handlers.h"
28
#include "zend_interfaces.h"
29
#include "zend_exceptions.h"
30
#include "zend_closures.h"
31
#include "zend_compile.h"
32
#include "zend_hash.h"
33
#include "zend_property_hooks.h"
34
#include "zend_observer.h"
35
36
#define DEBUG_OBJECT_HANDLERS 0
37
38
374
#define ZEND_WRONG_PROPERTY_OFFSET   0
39
2.52k
#define ZEND_HOOKED_PROPERTY_OFFSET 1
40
41
/* guard flags */
42
3.95k
#define IN_GET    ZEND_GUARD_PROPERTY_GET
43
2.12k
#define IN_SET    ZEND_GUARD_PROPERTY_SET
44
255
#define IN_UNSET  ZEND_GUARD_PROPERTY_UNSET
45
1.01k
#define IN_ISSET  ZEND_GUARD_PROPERTY_ISSET
46
#define IN_HOOK   ZEND_GUARD_PROPERTY_HOOK
47
48
static zend_arg_info zend_call_trampoline_arginfo[1] = {{0}};
49
static zend_arg_info zend_property_hook_arginfo[1] = {{0}};
50
51
static zend_always_inline bool zend_objects_check_stack_limit(void)
52
459
{
53
459
#ifdef ZEND_CHECK_STACK_LIMIT
54
459
  return zend_call_stack_overflowed(EG(stack_limit));
55
#else
56
  return false;
57
#endif
58
459
}
59
60
/*
61
  __X accessors explanation:
62
63
  if we have __get and property that is not part of the properties array is
64
  requested, we call __get handler. If it fails, we return uninitialized.
65
66
  if we have __set and property that is not part of the properties array is
67
  set, we call __set handler. If it fails, we do not change the array.
68
69
  for both handlers above, when we are inside __get/__set, no further calls for
70
  __get/__set for this property of this object will be made, to prevent endless
71
  recursion and enable accessors to change properties array.
72
73
  if we have __call and method which is not part of the class function table is
74
  called, we cal __call handler.
75
*/
76
77
ZEND_API HashTable *rebuild_object_properties_internal(zend_object *zobj) /* {{{ */
78
11.6k
{
79
11.6k
  if (!zobj->properties) {
80
11.4k
    zend_property_info *prop_info;
81
11.4k
    zend_class_entry *ce = zobj->ce;
82
11.4k
    int i;
83
84
11.4k
    zobj->properties = zend_new_array(ce->default_properties_count);
85
11.4k
    if (ce->default_properties_count) {
86
5.28k
      zend_hash_real_init_mixed(zobj->properties);
87
13.3k
      for (i = 0; i < ce->default_properties_count; i++) {
88
8.05k
        prop_info = ce->properties_info_table[i];
89
90
8.05k
        if (!prop_info) {
91
117
          continue;
92
117
        }
93
94
7.94k
        if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) {
95
1.06k
          HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
96
1.06k
        }
97
98
7.94k
        _zend_hash_append_ind(zobj->properties, prop_info->name,
99
7.94k
          OBJ_PROP(zobj, prop_info->offset));
100
7.94k
      }
101
5.28k
    }
102
11.4k
  }
103
104
11.6k
  return zobj->properties;
105
11.6k
}
106
/* }}} */
107
108
/* Implements the fast path for array cast */
109
ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /* {{{ */
110
72
{
111
72
  const zend_class_entry *ce = zobj->ce;
112
72
  HashTable *ht;
113
72
  zval* prop;
114
72
  int i;
115
116
72
  ZEND_ASSERT(!(zend_object_is_lazy_proxy(zobj) && zend_lazy_object_initialized(zobj)));
117
72
  ZEND_ASSERT(!zobj->properties);
118
72
  ht = zend_new_array(ce->default_properties_count);
119
72
  if (ce->default_properties_count) {
120
45
    zend_hash_real_init_mixed(ht);
121
102
    for (i = 0; i < ce->default_properties_count; i++) {
122
57
      const zend_property_info *prop_info = ce->properties_info_table[i];
123
124
57
      if (!prop_info) {
125
0
        continue;
126
0
      }
127
128
57
      prop = OBJ_PROP(zobj, prop_info->offset);
129
57
      if (UNEXPECTED(Z_TYPE_P(prop) == IS_UNDEF)) {
130
21
        continue;
131
21
      }
132
133
36
      if (Z_ISREF_P(prop) && Z_REFCOUNT_P(prop) == 1) {
134
6
        prop = Z_REFVAL_P(prop);
135
6
      }
136
137
36
      Z_TRY_ADDREF_P(prop);
138
36
      _zend_hash_append(ht, prop_info->name, prop);
139
36
    }
140
45
  }
141
72
  return ht;
142
72
}
143
/* }}} */
144
145
ZEND_API HashTable *zend_std_get_properties(zend_object *zobj) /* {{{ */
146
17.0k
{
147
17.0k
  return zend_std_get_properties_ex(zobj);
148
17.0k
}
149
/* }}} */
150
151
/* Fetch properties HashTable without triggering lazy initialization */
152
ZEND_API HashTable *zend_get_properties_no_lazy_init(zend_object *zobj)
153
609
{
154
609
  if (zobj->handlers->get_properties == zend_std_get_properties) {
155
609
    if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
156
609
        && zend_lazy_object_initialized(zobj))) {
157
15
      zend_object *instance = zend_lazy_object_get_instance(zobj);
158
15
      return zend_get_properties_no_lazy_init(instance);
159
15
    }
160
161
594
    if (!zobj->properties) {
162
396
      rebuild_object_properties_internal(zobj);
163
396
    }
164
594
    return zobj->properties;
165
609
  }
166
167
0
  ZEND_ASSERT(!zend_object_is_lazy(zobj));
168
169
0
  return zobj->handlers->get_properties(zobj);
170
0
}
171
172
ZEND_API HashTable *zend_std_get_gc(zend_object *zobj, zval **table, int *n) /* {{{ */
173
34.7k
{
174
34.7k
  if (zobj->handlers->get_properties != zend_std_get_properties) {
175
0
    *table = NULL;
176
0
    *n = 0;
177
0
    return zobj->handlers->get_properties(zobj);
178
34.7k
  } else {
179
34.7k
    if (UNEXPECTED(zend_object_is_lazy(zobj))) {
180
1.24k
      return zend_lazy_object_get_gc(zobj, table, n);
181
33.4k
    } else if (zobj->properties) {
182
8.36k
      *table = NULL;
183
8.36k
      *n = 0;
184
8.36k
      return zobj->properties;
185
25.0k
    } else {
186
25.0k
      *table = zobj->properties_table;
187
25.0k
      *n = zobj->ce->default_properties_count;
188
25.0k
      return NULL;
189
25.0k
    }
190
34.7k
  }
191
34.7k
}
192
/* }}} */
193
194
ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
195
5.24k
{
196
5.24k
  const zend_class_entry *ce = object->ce;
197
5.24k
  zval retval;
198
5.24k
  HashTable *ht;
199
200
5.24k
  if (!ce->__debugInfo) {
201
5.07k
    if (UNEXPECTED(zend_object_is_lazy(object))) {
202
600
      return zend_lazy_object_debug_info(object, is_temp);
203
600
    }
204
205
4.47k
    *is_temp = 0;
206
4.47k
    return object->handlers->get_properties(object);
207
5.07k
  }
208
209
174
  zend_call_known_instance_method_with_0_params(ce->__debugInfo, object, &retval);
210
174
  if (UNEXPECTED(Z_ISREF(retval))) {
211
3
    zend_unwrap_reference(&retval);
212
3
  }
213
174
  if (Z_TYPE(retval) == IS_ARRAY) {
214
159
    if (!Z_REFCOUNTED(retval)) {
215
18
      *is_temp = 1;
216
18
      return zend_array_dup(Z_ARRVAL(retval));
217
141
    } else if (Z_REFCOUNT(retval) <= 1) {
218
141
      *is_temp = 1;
219
141
      ht = Z_ARR(retval);
220
141
      return ht;
221
141
    } else {
222
0
      *is_temp = 0;
223
0
      zval_ptr_dtor(&retval);
224
0
      return Z_ARRVAL(retval);
225
0
    }
226
159
  } else if (Z_TYPE(retval) == IS_NULL) {
227
6
    zend_error(E_DEPRECATED, "Returning null from %s::__debugInfo() is deprecated, return an empty array instead",
228
6
      ZSTR_VAL(ce->name));
229
6
    *is_temp = 1;
230
6
    ht = zend_new_array(0);
231
6
    return ht;
232
6
  }
233
234
9
  zend_error_noreturn(E_ERROR, ZEND_DEBUGINFO_FUNC_NAME "() must return an array");
235
236
0
  return NULL; /* Compilers are dumb and don't understand that noreturn means that the function does NOT need a return value... */
237
174
}
238
/* }}} */
239
240
static void zend_std_call_getter(zend_object *zobj, zend_string *prop_name, zval *retval) /* {{{ */
241
1.21k
{
242
1.21k
  zval member;
243
1.21k
  ZVAL_STR(&member, prop_name);
244
1.21k
  zend_call_known_instance_method_with_1_params(zobj->ce->__get, zobj, retval, &member);
245
1.21k
}
246
/* }}} */
247
248
static void zend_std_call_setter(zend_object *zobj, zend_string *prop_name, zval *value) /* {{{ */
249
657
{
250
657
  zval args[2];
251
657
  ZVAL_STR(&args[0], prop_name);
252
657
  ZVAL_COPY_VALUE(&args[1], value);
253
657
  zend_call_known_instance_method(zobj->ce->__set, zobj, NULL, 2, args);
254
657
}
255
/* }}} */
256
257
static void zend_std_call_unsetter(zend_object *zobj, zend_string *prop_name) /* {{{ */
258
60
{
259
60
  zval member;
260
60
  ZVAL_STR(&member, prop_name);
261
60
  zend_call_known_instance_method_with_1_params(zobj->ce->__unset, zobj, NULL, &member);
262
60
}
263
/* }}} */
264
265
static void zend_std_call_issetter(zend_object *zobj, zend_string *prop_name, zval *retval) /* {{{ */
266
300
{
267
300
  zval member;
268
300
  ZVAL_STR(&member, prop_name);
269
300
  zend_call_known_instance_method_with_1_params(zobj->ce->__isset, zobj, retval, &member);
270
300
}
271
/* }}} */
272
273
274
static zend_always_inline bool is_derived_class(const zend_class_entry *child_class, const zend_class_entry *parent_class) /* {{{ */
275
452k
{
276
452k
  child_class = child_class->parent;
277
672k
  while (child_class) {
278
446k
    if (child_class == parent_class) {
279
226k
      return 1;
280
226k
    }
281
220k
    child_class = child_class->parent;
282
220k
  }
283
284
226k
  return 0;
285
452k
}
286
/* }}} */
287
288
static zend_never_inline int is_protected_compatible_scope(const zend_class_entry *ce, const zend_class_entry *scope) /* {{{ */
289
226k
{
290
226k
  return scope &&
291
226k
    (ce == scope || is_derived_class(ce, scope) || is_derived_class(scope, ce));
292
226k
}
293
/* }}} */
294
295
static zend_never_inline zend_property_info *zend_get_parent_private_property(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *member) /* {{{ */
296
360
{
297
360
  zval *zv;
298
360
  zend_property_info *prop_info;
299
300
360
  if (scope != ce && scope && is_derived_class(ce, scope)) {
301
288
    zv = zend_hash_find(&scope->properties_info, member);
302
288
    if (zv != NULL) {
303
288
      prop_info = (zend_property_info*)Z_PTR_P(zv);
304
288
      if ((prop_info->flags & ZEND_ACC_PRIVATE)
305
285
       && prop_info->ce == scope) {
306
276
        return prop_info;
307
276
      }
308
288
    }
309
288
  }
310
84
  return NULL;
311
360
}
312
/* }}} */
313
314
static ZEND_COLD zend_never_inline void zend_bad_property_access(const zend_property_info *property_info, const zend_class_entry *ce, const zend_string *member) /* {{{ */
315
63
{
316
63
  zend_throw_error(NULL, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ZSTR_VAL(ce->name), ZSTR_VAL(member));
317
63
}
318
/* }}} */
319
320
static ZEND_COLD zend_never_inline void zend_bad_property_name(void) /* {{{ */
321
18
{
322
18
  zend_throw_error(NULL, "Cannot access property starting with \"\\0\"");
323
18
}
324
/* }}} */
325
326
static ZEND_COLD zend_never_inline void zend_forbidden_dynamic_property(
327
36
    const zend_class_entry *ce, const zend_string *member) {
328
36
  zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
329
36
    ZSTR_VAL(ce->name), ZSTR_VAL(member));
330
36
}
331
332
static ZEND_COLD zend_never_inline bool zend_deprecated_dynamic_property(
333
1.70k
    zend_object *obj, const zend_string *member) {
334
1.70k
  GC_ADDREF(obj);
335
1.70k
  zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
336
1.70k
    ZSTR_VAL(obj->ce->name), ZSTR_VAL(member));
337
1.70k
  if (UNEXPECTED(GC_DELREF(obj) == 0)) {
338
0
    const zend_class_entry *ce = obj->ce;
339
0
    zend_objects_store_del(obj);
340
0
    if (!EG(exception)) {
341
      /* We cannot continue execution and have to throw an exception */
342
0
      zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
343
0
        ZSTR_VAL(ce->name), ZSTR_VAL(member));
344
0
    }
345
0
    return 0;
346
0
  }
347
1.70k
  return 1;
348
1.70k
}
349
350
static ZEND_COLD zend_never_inline void zend_readonly_property_unset_error(
351
21
    const zend_class_entry *ce, const zend_string *member) {
352
21
  zend_throw_error(NULL, "Cannot unset readonly property %s::$%s",
353
21
    ZSTR_VAL(ce->name), ZSTR_VAL(member));
354
21
}
355
356
static zend_always_inline const zend_class_entry *get_fake_or_executed_scope(void)
357
11.7M
{
358
11.7M
  if (UNEXPECTED(EG(fake_scope))) {
359
11.7M
    return EG(fake_scope);
360
11.7M
  } else {
361
4.75k
    return zend_get_executed_scope();
362
4.75k
  }
363
11.7M
}
364
365
static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *ce, zend_string *member, int silent, void **cache_slot, const zend_property_info **info_ptr) /* {{{ */
366
11.0M
{
367
11.0M
  zval *zv;
368
11.0M
  zend_property_info *property_info;
369
11.0M
  uint32_t flags;
370
11.0M
  uintptr_t offset;
371
372
11.0M
  if (cache_slot && EXPECTED(ce == CACHED_PTR_EX(cache_slot))) {
373
8.06k
    *info_ptr = CACHED_PTR_EX(cache_slot + 2);
374
8.06k
    return (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
375
8.06k
  }
376
377
11.0M
  if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
378
11.0M
   || UNEXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
379
9.07k
    if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0') && ZSTR_LEN(member) != 0) {
380
36
      if (!silent) {
381
18
        zend_bad_property_name();
382
18
      }
383
36
      return ZEND_WRONG_PROPERTY_OFFSET;
384
36
    }
385
9.07k
dynamic:
386
9.07k
    if (cache_slot) {
387
6.85k
      CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
388
6.85k
      CACHE_PTR_EX(cache_slot + 2, NULL);
389
6.85k
    }
390
9.07k
    return ZEND_DYNAMIC_PROPERTY_OFFSET;
391
9.07k
  }
392
393
11.0M
  property_info = (zend_property_info*)Z_PTR_P(zv);
394
11.0M
  flags = property_info->flags;
395
396
11.0M
  if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
397
11.0M
    const zend_class_entry *scope = get_fake_or_executed_scope();
398
399
11.0M
    if (property_info->ce != scope) {
400
226k
      if (flags & ZEND_ACC_CHANGED) {
401
240
        zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
402
403
        /* If there is a public/protected instance property on ce, don't try to use a
404
         * private static property on scope. If both are static, prefer the static
405
         * property on scope. This will throw a static property notice, rather than
406
         * a visibility error. */
407
240
        if (p && (!(p->flags & ZEND_ACC_STATIC) || (flags & ZEND_ACC_STATIC))) {
408
186
          property_info = p;
409
186
          flags = property_info->flags;
410
186
          goto found;
411
186
        } else if (flags & ZEND_ACC_PUBLIC) {
412
27
          goto found;
413
27
        }
414
240
      }
415
226k
      if (flags & ZEND_ACC_PRIVATE) {
416
232
        if (property_info->ce != ce) {
417
42
          goto dynamic;
418
190
        } else {
419
338
wrong:
420
          /* Information was available, but we were denied access.  Error out. */
421
338
          if (!silent) {
422
51
            zend_bad_property_access(property_info, ce, member);
423
51
          }
424
338
          return ZEND_WRONG_PROPERTY_OFFSET;
425
190
        }
426
226k
      } else {
427
226k
        ZEND_ASSERT(flags & ZEND_ACC_PROTECTED);
428
226k
        if (UNEXPECTED(!is_protected_compatible_scope(property_info->prototype->ce, scope))) {
429
148
          goto wrong;
430
148
        }
431
226k
      }
432
226k
    }
433
11.0M
  }
434
435
11.0M
found:
436
11.0M
  if (UNEXPECTED(flags & ZEND_ACC_STATIC)) {
437
54
    if (!silent) {
438
36
      zend_error(E_NOTICE, "Accessing static property %s::$%s as non static", ZSTR_VAL(ce->name), ZSTR_VAL(member));
439
36
    }
440
54
    return ZEND_DYNAMIC_PROPERTY_OFFSET;
441
54
  }
442
443
11.0M
  if (property_info->hooks) {
444
2.52k
    *info_ptr = property_info;
445
2.52k
    if (cache_slot) {
446
1.32k
      CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, (void*)ZEND_HOOKED_PROPERTY_OFFSET);
447
1.32k
      CACHE_PTR_EX(cache_slot + 2, property_info);
448
1.32k
    }
449
2.52k
    return ZEND_HOOKED_PROPERTY_OFFSET;
450
2.52k
  }
451
452
11.0M
  offset = property_info->offset;
453
11.0M
  if (EXPECTED(!ZEND_TYPE_IS_SET(property_info->type))) {
454
273k
    property_info = NULL;
455
10.7M
  } else {
456
10.7M
    *info_ptr = property_info;
457
10.7M
  }
458
11.0M
  if (cache_slot) {
459
10.2k
    CACHE_POLYMORPHIC_PTR_EX(cache_slot, ce, (void*)(uintptr_t)offset);
460
10.2k
    CACHE_PTR_EX(cache_slot + 2, property_info);
461
10.2k
  }
462
11.0M
  return offset;
463
11.0M
}
464
/* }}} */
465
466
static ZEND_COLD void zend_wrong_offset(zend_class_entry *ce, zend_string *member) /* {{{ */
467
21
{
468
21
  const zend_property_info *dummy;
469
470
  /* Trigger the correct error */
471
21
  zend_get_property_offset(ce, member, 0, NULL, &dummy);
472
21
}
473
/* }}} */
474
475
ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce, zend_string *member, int silent) /* {{{ */
476
717k
{
477
717k
  zval *zv;
478
717k
  zend_property_info *property_info;
479
717k
  uint32_t flags;
480
481
717k
  if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
482
717k
   || EXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
483
555
    if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0') && ZSTR_LEN(member) != 0) {
484
0
      if (!silent) {
485
0
        zend_bad_property_name();
486
0
      }
487
0
      return ZEND_WRONG_PROPERTY_INFO;
488
0
    }
489
612
dynamic:
490
612
    return NULL;
491
555
  }
492
493
717k
  property_info = (zend_property_info*)Z_PTR_P(zv);
494
717k
  flags = property_info->flags;
495
496
717k
  if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
497
714k
    const zend_class_entry *scope = get_fake_or_executed_scope();
498
714k
    if (property_info->ce != scope) {
499
350
      if (flags & ZEND_ACC_CHANGED) {
500
120
        zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
501
502
120
        if (p) {
503
78
          property_info = p;
504
78
          flags = property_info->flags;
505
78
          goto found;
506
78
        } else if (flags & ZEND_ACC_PUBLIC) {
507
6
          goto found;
508
6
        }
509
120
      }
510
266
      if (flags & ZEND_ACC_PRIVATE) {
511
242
        if (property_info->ce != ce) {
512
57
          goto dynamic;
513
185
        } else {
514
198
wrong:
515
          /* Information was available, but we were denied access.  Error out. */
516
198
          if (!silent) {
517
0
            zend_bad_property_access(property_info, ce, member);
518
0
          }
519
198
          return ZEND_WRONG_PROPERTY_INFO;
520
185
        }
521
242
      } else {
522
24
        ZEND_ASSERT(flags & ZEND_ACC_PROTECTED);
523
24
        if (UNEXPECTED(!is_protected_compatible_scope(property_info->prototype->ce, scope))) {
524
13
          goto wrong;
525
13
        }
526
24
      }
527
266
    }
528
714k
  }
529
530
717k
found:
531
717k
  if (UNEXPECTED(flags & ZEND_ACC_STATIC)) {
532
989
    if (!silent) {
533
0
      zend_error(E_NOTICE, "Accessing static property %s::$%s as non static", ZSTR_VAL(ce->name), ZSTR_VAL(member));
534
0
    }
535
989
  }
536
717k
  return property_info;
537
717k
}
538
/* }}} */
539
540
ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_string *prop_info_name, bool is_dynamic) /* {{{ */
541
1.28k
{
542
1.28k
  zend_property_info *property_info;
543
1.28k
  const char *class_name = NULL;
544
1.28k
  const char *prop_name;
545
1.28k
  zend_string *member;
546
1.28k
  size_t prop_name_len;
547
548
1.28k
  if (ZSTR_VAL(prop_info_name)[0] == 0) {
549
429
    if (is_dynamic) {
550
0
      return SUCCESS;
551
0
    }
552
553
429
    zend_unmangle_property_name_ex(prop_info_name, &class_name, &prop_name, &prop_name_len);
554
429
    member = zend_string_init(prop_name, prop_name_len, 0);
555
429
    property_info = zend_get_property_info(zobj->ce, member, 1);
556
429
    zend_string_release_ex(member, 0);
557
429
    if (property_info == NULL || property_info == ZEND_WRONG_PROPERTY_INFO) {
558
231
      return FAILURE;
559
231
    }
560
561
198
    if (class_name[0] != '*') {
562
156
      if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
563
        /* we we're looking for a private prop but found a non private one of the same name */
564
3
        return FAILURE;
565
153
      } else if (strcmp(ZSTR_VAL(prop_info_name)+1, ZSTR_VAL(property_info->name)+1)) {
566
        /* we we're looking for a private prop but found a private one of the same name but another class */
567
36
        return FAILURE;
568
36
      }
569
156
    } else {
570
      /* We were looking for a protected property but found a private one
571
       * belonging to the parent class. */
572
42
      if (property_info->flags & ZEND_ACC_PRIVATE) {
573
3
        return FAILURE;
574
3
      }
575
39
      ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
576
39
    }
577
156
    return SUCCESS;
578
858
  } else {
579
858
    property_info = zend_get_property_info(zobj->ce, prop_info_name, 1);
580
858
    if (property_info == NULL) {
581
84
      ZEND_ASSERT(is_dynamic);
582
84
      return SUCCESS;
583
774
    } else if (property_info == ZEND_WRONG_PROPERTY_INFO) {
584
0
      return FAILURE;
585
0
    }
586
774
    return (property_info->flags & ZEND_ACC_PUBLIC) ? SUCCESS : FAILURE;
587
858
  }
588
1.28k
}
589
/* }}} */
590
591
1.82k
ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_property_info *prop_info) {
592
1.82k
  ZEND_ASSERT(prop_info->flags & ZEND_ACC_PPP_SET_MASK);
593
1.82k
  ZEND_ASSERT(!(prop_info->flags & ZEND_ACC_PUBLIC_SET));
594
1.82k
  const zend_class_entry *scope = get_fake_or_executed_scope();
595
1.82k
  if (prop_info->ce == scope) {
596
1.36k
    return true;
597
1.36k
  }
598
456
  return EXPECTED((prop_info->flags & ZEND_ACC_PROTECTED_SET)
599
1.82k
    && is_protected_compatible_scope(prop_info->prototype->ce, scope));
600
1.82k
}
601
602
336
static void zend_property_guard_dtor(zval *el) /* {{{ */ {
603
336
  uint32_t *ptr = (uint32_t*)Z_PTR_P(el);
604
336
  if (EXPECTED(!(((uintptr_t)ptr) & 1))) {
605
195
    efree_size(ptr, sizeof(uint32_t));
606
195
  }
607
336
}
608
/* }}} */
609
610
static zend_always_inline zval *zend_get_guard_value(zend_object *zobj)
611
3.64k
{
612
3.64k
  return zobj->properties_table + zobj->ce->default_properties_count;
613
3.64k
}
614
615
ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *member) /* {{{ */
616
3.16k
{
617
3.16k
  HashTable *guards;
618
3.16k
  zval *zv;
619
3.16k
  uint32_t *ptr;
620
621
622
3.16k
  ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_USE_GUARDS);
623
3.16k
  zv = zend_get_guard_value(zobj);
624
3.16k
  if (EXPECTED(Z_TYPE_P(zv) == IS_STRING)) {
625
1.58k
    zend_string *str = Z_STR_P(zv);
626
1.58k
    if (EXPECTED(str == member) ||
627
        /* str and member don't necessarily have a pre-calculated hash value here */
628
1.07k
        EXPECTED(zend_string_equal_content(str, member))) {
629
1.07k
      return &Z_GUARD_P(zv);
630
1.07k
    } else if (EXPECTED(Z_GUARD_P(zv) == 0)) {
631
370
      zval_ptr_dtor_str(zv);
632
370
      ZVAL_STR_COPY(zv, member);
633
370
      return &Z_GUARD_P(zv);
634
370
    } else {
635
141
      ALLOC_HASHTABLE(guards);
636
141
      zend_hash_init(guards, 8, NULL, zend_property_guard_dtor, 0);
637
      /* mark pointer as "special" using low bit */
638
141
      zend_hash_add_new_ptr(guards, str,
639
141
        (void*)(((uintptr_t)&Z_GUARD_P(zv)) | 1));
640
141
      zval_ptr_dtor_str(zv);
641
141
      ZVAL_ARR(zv, guards);
642
141
    }
643
1.58k
  } else if (EXPECTED(Z_TYPE_P(zv) == IS_ARRAY)) {
644
759
    guards = Z_ARRVAL_P(zv);
645
759
    ZEND_ASSERT(guards != NULL);
646
759
    zv = zend_hash_find(guards, member);
647
759
    if (zv != NULL) {
648
705
      return (uint32_t*)(((uintptr_t)Z_PTR_P(zv)) & ~1);
649
705
    }
650
817
  } else {
651
817
    ZEND_ASSERT(Z_TYPE_P(zv) == IS_UNDEF);
652
817
    ZVAL_STR_COPY(zv, member);
653
817
    Z_GUARD_P(zv) &= ~ZEND_GUARD_PROPERTY_MASK;
654
817
    return &Z_GUARD_P(zv);
655
817
  }
656
  /* we have to allocate uint32_t separately because ht->arData may be reallocated */
657
195
  ptr = (uint32_t*)emalloc(sizeof(uint32_t));
658
195
  *ptr = 0;
659
195
  return (uint32_t*)zend_hash_add_new_ptr(guards, member, ptr);
660
3.16k
}
661
/* }}} */
662
663
ZEND_API uint32_t *zend_get_recursion_guard(zend_object *zobj)
664
6.67k
{
665
6.67k
  if (!(zobj->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
666
6.18k
    return NULL;
667
6.18k
  }
668
486
  zval *zv = zend_get_guard_value(zobj);
669
486
  return &Z_GUARD_P(zv);
670
6.67k
}
671
672
ZEND_COLD static void zend_typed_property_uninitialized_access(const zend_property_info *prop_info, zend_string *name)
673
126
{
674
126
  zend_throw_error(NULL, "Typed property %s::$%s must not be accessed before initialization",
675
126
    ZSTR_VAL(prop_info->ce->name),
676
126
    ZSTR_VAL(name));
677
126
}
678
679
static ZEND_FUNCTION(zend_parent_hook_get_trampoline);
680
static ZEND_FUNCTION(zend_parent_hook_set_trampoline);
681
682
static bool zend_is_in_hook(const zend_property_info *prop_info)
683
5.22k
{
684
5.22k
  const zend_execute_data *execute_data = EG(current_execute_data);
685
5.22k
  if (!execute_data || !EX(func) || !EX(func)->common.prop_info) {
686
3.99k
    return false;
687
3.99k
  }
688
689
1.22k
  const zend_property_info *parent_info = EX(func)->common.prop_info;
690
1.22k
  ZEND_ASSERT(prop_info->prototype && parent_info->prototype);
691
1.22k
  return prop_info->prototype == parent_info->prototype;
692
1.22k
}
693
694
static bool zend_should_call_hook(const zend_property_info *prop_info, const zend_object *obj)
695
4.87k
{
696
4.87k
  if (!zend_is_in_hook(prop_info)) {
697
4.16k
    return true;
698
4.16k
  }
699
700
  /* execute_data and This are guaranteed to be set if zend_is_in_hook() returns true. */
701
716
  zend_object *parent_obj = Z_OBJ(EG(current_execute_data)->This);
702
716
  if (parent_obj == obj) {
703
683
    return false;
704
683
  }
705
706
33
  if (zend_object_is_lazy_proxy(parent_obj)
707
21
   && zend_lazy_object_initialized(parent_obj)
708
21
   && zend_lazy_object_get_instance(parent_obj) == obj) {
709
21
    return false;
710
21
  }
711
712
12
  return true;
713
33
}
714
715
static ZEND_COLD void zend_throw_no_prop_backing_value_access(const zend_string *class_name, const zend_string *prop_name, bool is_read)
716
0
{
717
0
  zend_throw_error(NULL, "Must not %s virtual property %s::$%s",
718
0
    is_read ? "read from" : "write to",
719
0
    ZSTR_VAL(class_name), ZSTR_VAL(prop_name));
720
0
}
721
722
static bool zend_call_get_hook(
723
  const zend_property_info *prop_info, const zend_string *prop_name,
724
  zend_function *get, zend_object *zobj, zval *rv)
725
3.02k
{
726
3.02k
  if (!zend_should_call_hook(prop_info, zobj)) {
727
440
    if (UNEXPECTED(prop_info->flags & ZEND_ACC_VIRTUAL)) {
728
0
      zend_throw_no_prop_backing_value_access(zobj->ce->name, prop_name, /* is_read */ true);
729
0
    }
730
440
    return false;
731
440
  }
732
733
2.58k
  GC_ADDREF(zobj);
734
2.58k
  zend_call_known_instance_method_with_0_params(get, zobj, rv);
735
2.58k
  OBJ_RELEASE(zobj);
736
737
2.58k
  return true;
738
3.02k
}
739
740
ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int type, void **cache_slot, zval *rv) /* {{{ */
741
10.7M
{
742
10.7M
  zval *retval;
743
10.7M
  uintptr_t property_offset;
744
10.7M
  const zend_property_info *prop_info = NULL;
745
10.7M
  uint32_t *guard = NULL;
746
747
#if DEBUG_OBJECT_HANDLERS
748
  fprintf(stderr, "Read object #%d property: %s\n", zobj->handle, ZSTR_VAL(name));
749
#endif
750
751
  /* make zend_get_property_info silent if we have getter - we may want to use it */
752
10.7M
  property_offset = zend_get_property_offset(zobj->ce, name, (type == BP_VAR_IS) || (zobj->ce->__get != NULL), cache_slot, &prop_info);
753
754
10.7M
  if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
755
10.7M
try_again:
756
10.7M
    retval = OBJ_PROP(zobj, property_offset);
757
758
10.7M
    if (prop_info && UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))
759
1.20k
     && (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)
760
219
     && ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info))) {
761
219
      if (Z_TYPE_P(retval) == IS_OBJECT) {
762
        /* For objects, W/RW/UNSET fetch modes might not actually modify object.
763
         * Similar as with magic __get() allow them, but return the value as a copy
764
         * to make sure no actual modification is possible. */
765
87
        ZVAL_COPY(rv, retval);
766
87
        retval = rv;
767
87
        goto exit;
768
132
      } else if (Z_TYPE_P(retval) == IS_UNDEF && type == BP_VAR_UNSET) {
769
27
        retval = &EG(uninitialized_zval);
770
27
        goto exit;
771
27
      }
772
105
      if (prop_info->flags & ZEND_ACC_READONLY) {
773
66
        zend_readonly_property_indirect_modification_error(prop_info);
774
66
      } else {
775
39
        zend_asymmetric_visibility_property_modification_error(prop_info, "indirectly modify");
776
39
      }
777
105
      retval = &EG(uninitialized_zval);
778
105
      goto exit;
779
219
    }
780
10.7M
    if (EXPECTED(Z_TYPE_P(retval) != IS_UNDEF)) {
781
10.7M
      goto exit;
782
10.7M
    }
783
432
    if (UNEXPECTED(Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT)) {
784
      /* Skip __get() for uninitialized typed properties */
785
336
      goto uninit_error;
786
336
    }
787
8.68k
  } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
788
5.40k
    if (EXPECTED(zobj->properties != NULL)) {
789
1.19k
      if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(property_offset)) {
790
9
        uintptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(property_offset);
791
792
9
        if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
793
9
          Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
794
795
9
          if (EXPECTED(p->key == name) ||
796
0
                (EXPECTED(p->h == ZSTR_H(name)) &&
797
0
                 EXPECTED(p->key != NULL) &&
798
9
                 EXPECTED(zend_string_equal_content(p->key, name)))) {
799
9
            retval = &p->val;
800
9
            goto exit;
801
9
          }
802
9
        }
803
0
        CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
804
0
      }
805
1.18k
      retval = zend_hash_find(zobj->properties, name);
806
1.18k
      if (EXPECTED(retval)) {
807
591
        if (cache_slot) {
808
303
          uintptr_t idx = (char*)retval - (char*)zobj->properties->arData;
809
303
          CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
810
303
        }
811
591
        goto exit;
812
591
      }
813
1.18k
    }
814
5.40k
  } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
815
3.11k
    zend_function *get = prop_info->hooks[ZEND_PROPERTY_HOOK_GET];
816
3.11k
    if (!get) {
817
132
      if (prop_info->flags & ZEND_ACC_VIRTUAL) {
818
6
        zend_throw_error(NULL, "Cannot read from set-only virtual property %s::$%s",
819
6
          ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
820
6
        return &EG(uninitialized_zval);
821
6
      }
822
      /* Cache the fact that this hook has trivial read. This only applies to
823
       * BP_VAR_R and BP_VAR_IS fetches. */
824
126
      ZEND_SET_PROPERTY_HOOK_SIMPLE_READ(cache_slot);
825
826
126
      retval = OBJ_PROP(zobj, prop_info->offset);
827
126
      if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
828
        /* As hooked properties can't be unset, the only way to end up with an undef
829
         * value is via an uninitialized property. */
830
12
        ZEND_ASSERT(Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT);
831
12
        goto uninit_error;
832
12
      }
833
834
114
      if (UNEXPECTED(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)) {
835
9
        if (UNEXPECTED(Z_TYPE_P(retval) != IS_OBJECT)) {
836
9
          zend_throw_error(NULL, "Indirect modification of %s::$%s is not allowed",
837
9
            ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
838
9
          goto exit;
839
9
        }
840
0
        ZVAL_COPY(rv, retval);
841
0
        retval = rv;
842
0
      }
843
105
      goto exit;
844
114
    }
845
846
2.98k
    const zend_class_entry *ce = zobj->ce;
847
848
2.98k
    if (!zend_call_get_hook(prop_info, name, get, zobj, rv)) {
849
437
      if (EG(exception)) {
850
0
        return &EG(uninitialized_zval);
851
0
      }
852
853
      /* Reads from backing store can only occur in hooks, and hence will always remain simple. */
854
437
      const zend_execute_data *execute_data = EG(current_execute_data);
855
437
      if (cache_slot && EX(opline) && EX(opline)->opcode == ZEND_FETCH_OBJ_R && EX(opline)->op1_type == IS_UNUSED) {
856
224
        ZEND_SET_PROPERTY_HOOK_SIMPLE_READ(cache_slot);
857
224
      }
858
859
437
      property_offset = prop_info->offset;
860
437
      if (!ZEND_TYPE_IS_SET(prop_info->type)) {
861
368
        prop_info = NULL;
862
368
      }
863
437
      goto try_again;
864
437
    }
865
866
2.54k
    if (EXPECTED(cache_slot
867
2.54k
     && zend_execute_ex == execute_ex
868
2.54k
     && ce->default_object_handlers->read_property == zend_std_read_property
869
2.54k
     && !ce->create_object
870
2.54k
     && !zend_is_in_hook(prop_info)
871
2.54k
     && !(prop_info->hooks[ZEND_PROPERTY_HOOK_GET]->common.fn_flags & ZEND_ACC_RETURN_REFERENCE))) {
872
304
      ZEND_SET_PROPERTY_HOOK_SIMPLE_GET(cache_slot);
873
304
    }
874
875
2.54k
    if (Z_TYPE_P(rv) != IS_UNDEF) {
876
1.34k
      retval = rv;
877
1.34k
      if (!Z_ISREF_P(rv)
878
1.20k
       && (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)
879
48
       && UNEXPECTED(Z_TYPE_P(rv) != IS_OBJECT)) {
880
27
        zend_throw_error(NULL, "Indirect modification of %s::$%s is not allowed",
881
27
          ZSTR_VAL(ce->name), ZSTR_VAL(name));
882
27
      }
883
1.34k
    } else {
884
1.19k
      retval = &EG(uninitialized_zval);
885
1.19k
    }
886
887
2.54k
    goto exit;
888
2.98k
  } else if (UNEXPECTED(EG(exception))) {
889
21
    retval = &EG(uninitialized_zval);
890
21
    goto exit;
891
21
  }
892
893
5.04k
  retval = &EG(uninitialized_zval);
894
895
  /* For initialized lazy proxies: if the real instance's magic method
896
   * guard is already set for this property, we are inside a recursive
897
   * call from the real instance's __get/__isset. Forward directly to
898
   * the real instance to avoid double invocation. (GH-21478) */
899
5.04k
  if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
900
5.04k
      && zend_lazy_object_initialized(zobj))) {
901
51
    zend_object *instance = zend_lazy_object_get_instance(zobj);
902
51
    if (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS) {
903
39
      uint32_t *instance_guard = zend_get_property_guard(instance, name);
904
39
      uint32_t guard_type = ((type == BP_VAR_IS) && zobj->ce->__isset)
905
39
        ? IN_ISSET : IN_GET;
906
39
      if ((*instance_guard) & guard_type) {
907
15
        retval = zend_std_read_property(instance, name, type, cache_slot, rv);
908
15
        if (retval == &EG(uninitialized_zval)) {
909
9
          ZVAL_NULL(rv);
910
9
          retval = rv;
911
9
        }
912
15
        return retval;
913
15
      }
914
39
    }
915
51
  }
916
917
  /* magic isset */
918
5.02k
  if ((type == BP_VAR_IS) && zobj->ce->__isset) {
919
174
    zval tmp_result;
920
174
    guard = zend_get_property_guard(zobj, name);
921
922
174
    if (!((*guard) & IN_ISSET)) {
923
129
      GC_ADDREF(zobj);
924
925
129
      *guard |= IN_ISSET;
926
129
      zend_std_call_issetter(zobj, name, &tmp_result);
927
129
      *guard &= ~IN_ISSET;
928
929
129
      if (!zend_is_true(&tmp_result)) {
930
72
        retval = &EG(uninitialized_zval);
931
72
        OBJ_RELEASE(zobj);
932
72
        zval_ptr_dtor(&tmp_result);
933
72
        goto exit;
934
72
      }
935
936
57
      zval_ptr_dtor(&tmp_result);
937
57
      if (zobj->ce->__get && !((*guard) & IN_GET)) {
938
36
        goto call_getter;
939
36
      }
940
21
      OBJ_RELEASE(zobj);
941
45
    } else if (zobj->ce->__get && !((*guard) & IN_GET)) {
942
15
      goto call_getter_addref;
943
15
    }
944
4.85k
  } else if (zobj->ce->__get) {
945
    /* magic get */
946
1.33k
    guard = zend_get_property_guard(zobj, name);
947
1.33k
    if (!((*guard) & IN_GET)) {
948
      /* have getter - try with it! */
949
1.16k
call_getter_addref:
950
1.16k
      GC_ADDREF(zobj);
951
1.20k
call_getter:
952
1.20k
      *guard |= IN_GET; /* prevent circular getting */
953
1.20k
      zend_std_call_getter(zobj, name, rv);
954
1.20k
      *guard &= ~IN_GET;
955
956
1.20k
      if (Z_TYPE_P(rv) != IS_UNDEF) {
957
1.11k
        retval = rv;
958
1.11k
        if (!Z_ISREF_P(rv) &&
959
731
            (type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET)) {
960
153
          if (UNEXPECTED(Z_TYPE_P(rv) != IS_OBJECT)) {
961
114
            zend_error(E_NOTICE, "Indirect modification of overloaded property %s::$%s has no effect", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
962
114
          }
963
153
        }
964
1.11k
      } else {
965
87
        retval = &EG(uninitialized_zval);
966
87
      }
967
968
1.20k
      if (prop_info) {
969
27
        zend_verify_prop_assignable_by_ref_ex(prop_info, retval, (zobj->ce->__get->common.fn_flags & ZEND_ACC_STRICT_TYPES) != 0, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET);
970
27
      }
971
972
1.20k
      OBJ_RELEASE(zobj);
973
1.20k
      goto exit;
974
1.16k
    } else if (UNEXPECTED(IS_WRONG_PROPERTY_OFFSET(property_offset))) {
975
      /* Trigger the correct error */
976
9
      zend_wrong_offset(zobj->ce, name);
977
9
      ZEND_ASSERT(EG(exception));
978
9
      retval = &EG(uninitialized_zval);
979
9
      goto exit;
980
9
    }
981
1.33k
  }
982
983
4.09k
uninit_error:
984
4.09k
  if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
985
333
    if (!prop_info || (Z_PROP_FLAG_P(retval) & IS_PROP_LAZY)) {
986
324
      zend_object *instance = zend_lazy_object_init(zobj);
987
324
      if (!instance) {
988
48
        retval = &EG(uninitialized_zval);
989
48
        goto exit;
990
48
      }
991
992
276
      if (UNEXPECTED(guard && (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS))) {
993
        /* Find which guard was used on zobj, so we can set the same
994
         * guard on instance. */
995
24
        uint32_t guard_type = (type == BP_VAR_IS) && zobj->ce->__isset
996
24
          ? IN_ISSET : IN_GET;
997
24
        guard = zend_get_property_guard(instance, name);
998
24
        if (!((*guard) & guard_type)) {
999
18
          (*guard) |= guard_type;
1000
18
          retval = zend_std_read_property(instance, name, type, cache_slot, rv);
1001
18
          (*guard) &= ~guard_type;
1002
18
          return retval;
1003
18
        }
1004
24
      }
1005
1006
258
      return zend_std_read_property(instance, name, type, cache_slot, rv);
1007
276
    }
1008
333
  }
1009
3.76k
  if (type != BP_VAR_IS) {
1010
3.46k
    if (prop_info) {
1011
81
      zend_typed_property_uninitialized_access(prop_info, name);
1012
3.38k
    } else {
1013
3.38k
      zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1014
3.38k
    }
1015
3.46k
  }
1016
3.76k
  retval = &EG(uninitialized_zval);
1017
1018
10.7M
exit:
1019
10.7M
  return retval;
1020
3.76k
}
1021
/* }}} */
1022
1023
356k
static zend_always_inline bool property_uses_strict_types(void) {
1024
356k
  const zend_execute_data *execute_data = EG(current_execute_data);
1025
356k
  return execute_data
1026
338k
    && execute_data->func
1027
338k
    && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data));
1028
356k
}
1029
1030
static zval *forward_write_to_lazy_object(zend_object *zobj,
1031
    zend_string *name, zval *value, void **cache_slot, bool guarded)
1032
141
{
1033
141
  zval *variable_ptr;
1034
1035
  /* backup value as it may change during initialization */
1036
141
  zval backup;
1037
141
  ZVAL_COPY(&backup, value);
1038
1039
141
  zend_object *instance = zend_lazy_object_init(zobj);
1040
141
  if (UNEXPECTED(!instance)) {
1041
33
    zval_ptr_dtor(&backup);
1042
33
    return &EG(error_zval);
1043
33
  }
1044
1045
108
  if (UNEXPECTED(guarded && (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS))) {
1046
12
    uint32_t *guard = zend_get_property_guard(instance, name);
1047
12
    if (!((*guard) & IN_SET)) {
1048
9
      (*guard) |= IN_SET;
1049
9
      variable_ptr = zend_std_write_property(instance, name, &backup, cache_slot);
1050
9
      (*guard) &= ~IN_SET;
1051
9
      goto exit;
1052
9
    }
1053
12
  }
1054
1055
99
  variable_ptr = zend_std_write_property(instance, name, &backup, cache_slot);
1056
1057
108
exit:
1058
108
  zval_ptr_dtor(&backup);
1059
1060
108
  if (variable_ptr == &backup) {
1061
0
    variable_ptr = value;
1062
0
  }
1063
1064
108
  return variable_ptr;
1065
99
}
1066
1067
ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) /* {{{ */
1068
302k
{
1069
302k
  zval *variable_ptr, tmp;
1070
302k
  uintptr_t property_offset;
1071
302k
  const zend_property_info *prop_info = NULL;
1072
302k
  uint32_t *guard = NULL;
1073
302k
  ZEND_ASSERT(!Z_ISREF_P(value));
1074
1075
302k
  property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__set != NULL), cache_slot, &prop_info);
1076
1077
302k
  if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1078
297k
try_again:
1079
297k
    variable_ptr = OBJ_PROP(zobj, property_offset);
1080
1081
297k
    if (prop_info && UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1082
1.76k
      bool error;
1083
1.76k
      if (Z_TYPE_P(variable_ptr) != IS_UNDEF || (Z_PROP_FLAG_P(variable_ptr) & IS_PROP_UNINIT) || !zobj->ce->__set) {
1084
1.75k
        error = true;
1085
1.75k
      } else {
1086
12
        guard = zend_get_property_guard(zobj, name);
1087
12
        error = (*guard) & IN_SET;
1088
12
      }
1089
1.76k
      if (error) {
1090
1.75k
        if ((prop_info->flags & ZEND_ACC_READONLY)
1091
1.27k
         && Z_TYPE_P(variable_ptr) != IS_UNDEF
1092
165
         && !(Z_PROP_FLAG_P(variable_ptr) & IS_PROP_REINITABLE)) {
1093
132
          zend_readonly_property_modification_error(prop_info);
1094
132
          variable_ptr = &EG(error_zval);
1095
132
          goto exit;
1096
132
        }
1097
1.62k
        if ((prop_info->flags & ZEND_ACC_PPP_SET_MASK) && !zend_asymmetric_property_has_set_access(prop_info)) {
1098
108
          zend_asymmetric_visibility_property_modification_error(prop_info, "modify");
1099
108
          variable_ptr = &EG(error_zval);
1100
108
          goto exit;
1101
108
        }
1102
1.62k
      }
1103
1.76k
    }
1104
1105
297k
    if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
1106
293k
      Z_TRY_ADDREF_P(value);
1107
1108
293k
      if (prop_info) {
1109
59.6k
typed_property:
1110
59.6k
        ZVAL_COPY_VALUE(&tmp, value);
1111
        // Increase refcount to prevent object from being released in __toString()
1112
59.6k
        GC_ADDREF(zobj);
1113
59.6k
        bool type_matched = zend_verify_property_type(prop_info, &tmp, property_uses_strict_types());
1114
59.6k
        if (UNEXPECTED(GC_DELREF(zobj) == 0)) {
1115
6
          zend_object_released_while_assigning_to_property_error(prop_info);
1116
6
          zend_objects_store_del(zobj);
1117
6
          zval_ptr_dtor(&tmp);
1118
6
          variable_ptr = &EG(error_zval);
1119
6
          goto exit;
1120
6
        }
1121
59.6k
        if (UNEXPECTED(!type_matched)) {
1122
201
          zval_ptr_dtor(&tmp);
1123
201
          variable_ptr = &EG(error_zval);
1124
201
          goto exit;
1125
201
        }
1126
59.4k
        Z_PROP_FLAG_P(variable_ptr) &= ~(IS_PROP_UNINIT|IS_PROP_REINITABLE);
1127
59.4k
        value = &tmp;
1128
59.4k
      }
1129
1130
297k
found:;
1131
297k
      zend_refcounted *garbage = NULL;
1132
1133
297k
      variable_ptr = zend_assign_to_variable_ex(
1134
297k
        variable_ptr, value, IS_TMP_VAR, property_uses_strict_types(), &garbage);
1135
1136
297k
      if (garbage) {
1137
1.12k
        if (GC_DELREF(garbage) == 0) {
1138
366
          zend_execute_data *execute_data = EG(current_execute_data);
1139
          // Assign to result variable before calling the destructor as it may release the object
1140
366
          if (execute_data
1141
366
           && EX(func)
1142
366
           && ZEND_USER_CODE(EX(func)->common.type)
1143
151
           && EX(opline)
1144
151
           && EX(opline)->opcode == ZEND_ASSIGN_OBJ
1145
151
           && EX(opline)->result_type) {
1146
51
            ZVAL_COPY_DEREF(EX_VAR(EX(opline)->result.var), variable_ptr);
1147
51
            variable_ptr = NULL;
1148
51
          }
1149
366
          rc_dtor_func(garbage);
1150
756
        } else {
1151
756
          gc_check_possible_root_no_ref(garbage);
1152
756
        }
1153
1.12k
      }
1154
297k
      goto exit;
1155
293k
    }
1156
3.59k
    if (Z_PROP_FLAG_P(variable_ptr) & IS_PROP_UNINIT) {
1157
3.51k
      if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
1158
430
        if (Z_PROP_FLAG_P(variable_ptr) & IS_PROP_LAZY) {
1159
120
          goto lazy_init;
1160
120
        }
1161
430
      }
1162
      /* Writes to uninitialized typed properties bypass __set(). */
1163
3.39k
      goto write_std_property;
1164
3.51k
    }
1165
5.60k
  } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
1166
3.81k
    if (EXPECTED(zobj->properties != NULL)) {
1167
1.32k
      if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
1168
24
        if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
1169
24
          GC_DELREF(zobj->properties);
1170
24
        }
1171
24
        zobj->properties = zend_array_dup(zobj->properties);
1172
24
      }
1173
1.32k
      if ((variable_ptr = zend_hash_find(zobj->properties, name)) != NULL) {
1174
652
        Z_TRY_ADDREF_P(value);
1175
652
        goto found;
1176
652
      }
1177
1.32k
    }
1178
3.81k
  } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
1179
1.69k
    zend_function *set = prop_info->hooks[ZEND_PROPERTY_HOOK_SET];
1180
1181
1.69k
    if (!set) {
1182
33
      if (prop_info->flags & ZEND_ACC_VIRTUAL) {
1183
6
        zend_throw_error(NULL, "Cannot write to get-only virtual property %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1184
6
        variable_ptr = &EG(error_zval);
1185
6
        goto exit;
1186
6
      }
1187
27
      ZEND_SET_PROPERTY_HOOK_SIMPLE_WRITE(cache_slot);
1188
27
      property_offset = prop_info->offset;
1189
27
      if (!ZEND_TYPE_IS_SET(prop_info->type)) {
1190
18
        prop_info = NULL;
1191
18
      }
1192
27
      goto try_again;
1193
33
    }
1194
1195
1.66k
    if (!zend_should_call_hook(prop_info, zobj)) {
1196
204
      if (prop_info->flags & ZEND_ACC_VIRTUAL) {
1197
0
        zend_throw_no_prop_backing_value_access(zobj->ce->name, name, /* is_read */ false);
1198
0
        variable_ptr = &EG(error_zval);
1199
0
        goto exit;
1200
0
      }
1201
1202
      /* Writes to backing store can only occur in hooks, and hence will always remain simple. */
1203
204
      zend_execute_data *execute_data = EG(current_execute_data);
1204
204
      if (cache_slot && EX(opline) && EX(opline)->opcode == ZEND_ASSIGN_OBJ && EX(opline)->op1_type == IS_UNUSED) {
1205
192
        ZEND_SET_PROPERTY_HOOK_SIMPLE_WRITE(cache_slot);
1206
192
      }
1207
1208
204
      property_offset = prop_info->offset;
1209
204
      if (!ZEND_TYPE_IS_SET(prop_info->type)) {
1210
105
        prop_info = NULL;
1211
105
      }
1212
204
      goto try_again;
1213
204
    }
1214
1215
1.45k
    if (UNEXPECTED(prop_info->flags & ZEND_ACC_PPP_SET_MASK
1216
1.45k
     && !zend_asymmetric_property_has_set_access(prop_info))) {
1217
3
      zend_asymmetric_visibility_property_modification_error(prop_info, "modify");
1218
3
      variable_ptr = &EG(error_zval);
1219
3
      goto exit;
1220
3
    }
1221
1222
1.45k
    GC_ADDREF(zobj);
1223
1.45k
    zend_call_known_instance_method_with_1_params(set, zobj, NULL, value);
1224
1.45k
    OBJ_RELEASE(zobj);
1225
1226
1.45k
    variable_ptr = value;
1227
1.45k
    goto exit;
1228
1.45k
  } else if (UNEXPECTED(EG(exception))) {
1229
18
    variable_ptr = &EG(error_zval);
1230
18
    goto exit;
1231
18
  }
1232
1233
  /* For initialized lazy proxies: if the real instance's __set guard
1234
   * is already set, we are inside a recursive call from the real
1235
   * instance's __set. Forward directly to avoid double invocation. */
1236
3.32k
  if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
1237
3.32k
      && zend_lazy_object_initialized(zobj))) {
1238
18
    zend_object *instance = zend_lazy_object_get_instance(zobj);
1239
18
    if (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS) {
1240
18
      uint32_t *instance_guard = zend_get_property_guard(instance, name);
1241
18
      if ((*instance_guard) & IN_SET) {
1242
9
        return zend_std_write_property(instance, name, value, cache_slot);
1243
9
      }
1244
18
    }
1245
18
  }
1246
1247
  /* magic set */
1248
3.31k
  if (zobj->ce->__set) {
1249
750
    if (!guard) {
1250
741
      guard = zend_get_property_guard(zobj, name);
1251
741
    }
1252
1253
750
    if (!((*guard) & IN_SET)) {
1254
657
      GC_ADDREF(zobj);
1255
657
      (*guard) |= IN_SET; /* prevent circular setting */
1256
657
      zend_std_call_setter(zobj, name, value);
1257
657
      (*guard) &= ~IN_SET;
1258
657
      OBJ_RELEASE(zobj);
1259
657
      variable_ptr = value;
1260
657
    } else if (EXPECTED(!IS_WRONG_PROPERTY_OFFSET(property_offset))) {
1261
87
      if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
1262
12
        return forward_write_to_lazy_object(zobj, name, value,
1263
12
            cache_slot, /* guarded */ true);
1264
12
      }
1265
1266
75
      goto write_std_property;
1267
87
    } else {
1268
      /* Trigger the correct error */
1269
6
      zend_wrong_offset(zobj->ce, name);
1270
6
      ZEND_ASSERT(EG(exception));
1271
6
      variable_ptr = &EG(error_zval);
1272
6
      goto exit;
1273
6
    }
1274
2.56k
  } else {
1275
2.56k
    ZEND_ASSERT(!IS_WRONG_PROPERTY_OFFSET(property_offset));
1276
2.56k
    if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
1277
9
      goto lazy_init;
1278
9
    }
1279
6.02k
write_std_property:
1280
6.02k
    if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1281
3.44k
      variable_ptr = OBJ_PROP(zobj, property_offset);
1282
1283
3.44k
      Z_TRY_ADDREF_P(value);
1284
3.44k
      if (prop_info) {
1285
3.25k
        goto typed_property;
1286
3.25k
      }
1287
1288
196
      ZVAL_COPY_VALUE(variable_ptr, value);
1289
2.58k
    } else {
1290
2.58k
      if (UNEXPECTED(zobj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) {
1291
27
        zend_forbidden_dynamic_property(zobj->ce, name);
1292
27
        variable_ptr = &EG(error_zval);
1293
27
        goto exit;
1294
27
      }
1295
2.55k
      if (UNEXPECTED(!(zobj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES))) {
1296
1.30k
        if (UNEXPECTED(!zend_deprecated_dynamic_property(zobj, name))) {
1297
0
          variable_ptr = &EG(error_zval);
1298
0
          goto exit;
1299
0
        }
1300
1.30k
      }
1301
1302
2.55k
      Z_TRY_ADDREF_P(value);
1303
2.55k
      variable_ptr = zend_hash_add_new(zend_std_get_properties(zobj), name, value);
1304
2.55k
    }
1305
6.02k
  }
1306
1307
301k
exit:
1308
301k
  return variable_ptr;
1309
1310
129
lazy_init:
1311
129
  return forward_write_to_lazy_object(zobj, name, value, cache_slot,
1312
129
      /* guarded */ false);
1313
3.31k
}
1314
/* }}} */
1315
1316
static ZEND_COLD zend_never_inline void zend_bad_array_access(const zend_class_entry *ce) /* {{{ */
1317
27
{
1318
27
  zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(ce->name));
1319
27
}
1320
/* }}} */
1321
1322
ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int type, zval *rv) /* {{{ */
1323
396
{
1324
396
  const zend_class_entry *ce = object->ce;
1325
396
  zval tmp_offset;
1326
1327
  /* arrayaccess_funcs_ptr is set if (and only if) the class implements zend_ce_arrayaccess */
1328
396
  zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
1329
396
  if (EXPECTED(funcs)) {
1330
375
    if (offset == NULL) {
1331
      /* [] construct */
1332
6
      ZVAL_NULL(&tmp_offset);
1333
369
    } else {
1334
369
      ZVAL_COPY_DEREF(&tmp_offset, offset);
1335
369
    }
1336
1337
375
    GC_ADDREF(object);
1338
375
    if (type == BP_VAR_IS) {
1339
105
      zend_call_known_instance_method_with_1_params(funcs->zf_offsetexists, object, rv, &tmp_offset);
1340
105
      if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
1341
0
        OBJ_RELEASE(object);
1342
0
        zval_ptr_dtor(&tmp_offset);
1343
0
        return NULL;
1344
0
      }
1345
105
      if (!i_zend_is_true(rv)) {
1346
51
        OBJ_RELEASE(object);
1347
51
        zval_ptr_dtor(&tmp_offset);
1348
51
        zval_ptr_dtor(rv);
1349
51
        return &EG(uninitialized_zval);
1350
51
      }
1351
54
      zval_ptr_dtor(rv);
1352
54
    }
1353
1354
324
    zend_call_known_instance_method_with_1_params(funcs->zf_offsetget, object, rv, &tmp_offset);
1355
1356
324
    OBJ_RELEASE(object);
1357
324
    zval_ptr_dtor(&tmp_offset);
1358
1359
324
    if (UNEXPECTED(Z_TYPE_P(rv) == IS_UNDEF)) {
1360
9
      if (UNEXPECTED(!EG(exception))) {
1361
0
        zend_throw_error(NULL, "Undefined offset for object of type %s used as array", ZSTR_VAL(ce->name));
1362
0
      }
1363
9
      return NULL;
1364
9
    }
1365
315
    return rv;
1366
324
  } else {
1367
21
      zend_bad_array_access(ce);
1368
21
    return NULL;
1369
21
  }
1370
396
}
1371
/* }}} */
1372
1373
ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval *value) /* {{{ */
1374
198
{
1375
198
  const zend_class_entry *ce = object->ce;
1376
198
  zval tmp_offset;
1377
1378
198
  zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
1379
198
  if (EXPECTED(funcs)) {
1380
195
    if (!offset) {
1381
18
      ZVAL_NULL(&tmp_offset);
1382
177
    } else {
1383
177
      ZVAL_COPY_DEREF(&tmp_offset, offset);
1384
177
    }
1385
195
    GC_ADDREF(object);
1386
195
    zend_call_known_instance_method_with_2_params(funcs->zf_offsetset, object, NULL, &tmp_offset, value);
1387
195
    OBJ_RELEASE(object);
1388
195
    zval_ptr_dtor(&tmp_offset);
1389
195
  } else {
1390
3
      zend_bad_array_access(ce);
1391
3
  }
1392
198
}
1393
/* }}} */
1394
1395
// todo: make zend_std_has_dimension return bool as well
1396
ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */
1397
102
{
1398
102
  const zend_class_entry *ce = object->ce;
1399
102
  zval retval, tmp_offset;
1400
102
  bool result;
1401
1402
102
  zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
1403
102
  if (EXPECTED(funcs)) {
1404
102
    ZVAL_COPY_DEREF(&tmp_offset, offset);
1405
102
    GC_ADDREF(object);
1406
102
    zend_call_known_instance_method_with_1_params(funcs->zf_offsetexists, object, &retval, &tmp_offset);
1407
102
    result = i_zend_is_true(&retval);
1408
102
    zval_ptr_dtor(&retval);
1409
102
    if (check_empty && result && EXPECTED(!EG(exception))) {
1410
12
      zend_call_known_instance_method_with_1_params(funcs->zf_offsetget, object, &retval, &tmp_offset);
1411
12
      result = i_zend_is_true(&retval);
1412
12
      zval_ptr_dtor(&retval);
1413
12
    }
1414
102
    OBJ_RELEASE(object);
1415
102
    zval_ptr_dtor(&tmp_offset);
1416
102
  } else {
1417
0
      zend_bad_array_access(ce);
1418
0
    return 0;
1419
0
  }
1420
1421
102
  return result;
1422
102
}
1423
/* }}} */
1424
1425
ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) /* {{{ */
1426
5.42k
{
1427
5.42k
  zval *retval = NULL;
1428
5.42k
  uintptr_t property_offset;
1429
5.42k
  const zend_property_info *prop_info = NULL;
1430
1431
5.42k
  ZEND_ASSERT(type != BP_VAR_R && type != BP_VAR_IS);
1432
1433
#if DEBUG_OBJECT_HANDLERS
1434
  fprintf(stderr, "Ptr object #%d property: %s\n", zobj->handle, ZSTR_VAL(name));
1435
#endif
1436
1437
5.42k
  property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__get != NULL), cache_slot, &prop_info);
1438
1439
5.42k
  if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1440
3.26k
try_again:
1441
3.26k
    retval = OBJ_PROP(zobj, property_offset);
1442
3.26k
    if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
1443
420
      if (EXPECTED(!zobj->ce->__get) ||
1444
18
          UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET) ||
1445
405
          UNEXPECTED(prop_info && (Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT))) {
1446
405
        if (UNEXPECTED(zend_lazy_object_must_init(zobj) && (Z_PROP_FLAG_P(retval) & IS_PROP_LAZY))) {
1447
111
          bool guarded = zobj->ce->__get
1448
0
            && (*zend_get_property_guard(zobj, name) & IN_GET);
1449
111
          zend_object *instance = zend_lazy_object_init(zobj);
1450
111
          if (!instance) {
1451
9
            return &EG(error_zval);
1452
9
          }
1453
1454
102
          if (guarded && (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
1455
0
            uint32_t *guard = zend_get_property_guard(instance, name);
1456
0
            if (!(*guard & IN_GET)) {
1457
0
              (*guard) |= IN_GET;
1458
0
              retval = zend_std_get_property_ptr_ptr(instance, name, type, cache_slot);
1459
0
              (*guard) &= ~IN_GET;
1460
0
              return retval;
1461
0
            }
1462
0
          }
1463
1464
102
          return zend_std_get_property_ptr_ptr(instance, name, type, cache_slot);
1465
102
        }
1466
294
        if (UNEXPECTED(type == BP_VAR_RW)) {
1467
54
          if (prop_info) {
1468
45
            zend_typed_property_uninitialized_access(prop_info, name);
1469
45
            retval = &EG(error_zval);
1470
45
          } else {
1471
9
            zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1472
            /* An error handler may set the property */
1473
9
             if (EXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
1474
9
              ZVAL_NULL(retval);
1475
9
             }
1476
9
          }
1477
240
        } else if (prop_info && UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1478
81
          if ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info)) {
1479
69
            retval = NULL;
1480
69
          }
1481
159
        } else if (!prop_info || !ZEND_TYPE_IS_SET(prop_info->type)) {
1482
12
          ZVAL_NULL(retval);
1483
12
        }
1484
294
      } else {
1485
        /* we do have getter - fail and let it try again with usual get/set */
1486
15
        retval = NULL;
1487
15
      }
1488
2.84k
    } else if (prop_info && UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1489
285
      if ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info)) {
1490
261
        retval = NULL;
1491
261
      }
1492
285
    }
1493
3.26k
  } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
1494
1.91k
    if (EXPECTED(zobj->properties)) {
1495
976
      if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
1496
21
        if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
1497
21
          GC_DELREF(zobj->properties);
1498
21
        }
1499
21
        zobj->properties = zend_array_dup(zobj->properties);
1500
21
      }
1501
976
        if (EXPECTED((retval = zend_hash_find(zobj->properties, name)) != NULL)) {
1502
622
        return retval;
1503
622
        }
1504
976
    }
1505
1.29k
    if (EXPECTED(!zobj->ce->__get) ||
1506
896
        UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET)) {
1507
896
      if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
1508
57
        bool guarded = (zobj->ce->__get != NULL);
1509
57
        zend_object *instance = zend_lazy_object_init(zobj);
1510
57
        if (!instance) {
1511
6
          return &EG(error_zval);
1512
6
        }
1513
1514
51
        if (guarded && (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
1515
12
          uint32_t *guard = zend_get_property_guard(instance, name);
1516
12
          if (!(*guard & IN_GET)) {
1517
12
            (*guard) |= IN_GET;
1518
12
            retval = zend_std_get_property_ptr_ptr(instance, name, type, cache_slot);
1519
12
            (*guard) &= ~IN_GET;
1520
12
            return retval;
1521
12
          }
1522
12
        }
1523
1524
39
        return zend_std_get_property_ptr_ptr(instance, name, type, cache_slot);
1525
51
      }
1526
839
      if (UNEXPECTED(zobj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) {
1527
9
        zend_forbidden_dynamic_property(zobj->ce, name);
1528
9
        return &EG(error_zval);
1529
9
      }
1530
830
      if (UNEXPECTED(!(zobj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES))) {
1531
392
        if (UNEXPECTED(!zend_deprecated_dynamic_property(zobj, name))) {
1532
0
          return &EG(error_zval);
1533
0
        }
1534
392
      }
1535
830
      if (UNEXPECTED(!zobj->properties)) {
1536
509
        rebuild_object_properties_internal(zobj);
1537
509
      }
1538
830
      if (UNEXPECTED(type == BP_VAR_RW)) {
1539
195
        zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1540
195
      }
1541
830
      retval = zend_hash_add(zobj->properties, name, &EG(uninitialized_zval));
1542
830
    }
1543
1.29k
  } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
1544
246
    if (!(prop_info->flags & ZEND_ACC_VIRTUAL) && !zend_should_call_hook(prop_info, zobj)) {
1545
60
      property_offset = prop_info->offset;
1546
60
      if (!ZEND_TYPE_IS_SET(prop_info->type)) {
1547
57
        prop_info = NULL;
1548
57
      }
1549
60
      goto try_again;
1550
60
    }
1551
246
  } else if (zobj->ce->__get == NULL) {
1552
6
    retval = &EG(error_zval);
1553
6
  }
1554
1555
4.62k
  return retval;
1556
5.42k
}
1557
/* }}} */
1558
1559
ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) /* {{{ */
1560
699
{
1561
699
  uintptr_t property_offset;
1562
699
  const zend_property_info *prop_info = NULL;
1563
699
  uint32_t *guard = NULL;
1564
1565
699
  property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__unset != NULL), cache_slot, &prop_info);
1566
1567
699
  if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1568
429
    zval *slot = OBJ_PROP(zobj, property_offset);
1569
1570
429
    if (prop_info && UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1571
135
      bool error;
1572
135
      if (Z_TYPE_P(slot) != IS_UNDEF || Z_PROP_FLAG_P(slot) & IS_PROP_UNINIT || !zobj->ce->__unset) {
1573
120
        error = true;
1574
120
      } else {
1575
15
        guard = zend_get_property_guard(zobj, name);
1576
15
        error = (*guard) & IN_UNSET;
1577
15
      }
1578
135
      if (error) {
1579
123
        if ((prop_info->flags & ZEND_ACC_READONLY)
1580
45
         && Z_TYPE_P(slot) != IS_UNDEF
1581
24
         && !(Z_PROP_FLAG_P(slot) & IS_PROP_REINITABLE)) {
1582
21
          zend_readonly_property_unset_error(prop_info->ce, name);
1583
21
          return;
1584
21
        }
1585
102
        if ((prop_info->flags & ZEND_ACC_PPP_SET_MASK) && !zend_asymmetric_property_has_set_access(prop_info)) {
1586
45
          zend_asymmetric_visibility_property_modification_error(prop_info, "unset");
1587
45
          return;
1588
45
        }
1589
102
      }
1590
135
    }
1591
1592
363
    if (Z_TYPE_P(slot) != IS_UNDEF) {
1593
282
      if (UNEXPECTED(Z_ISREF_P(slot)) &&
1594
48
          (ZEND_DEBUG || ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(slot)))) {
1595
48
        if (prop_info) {
1596
45
          ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(slot), prop_info);
1597
45
        }
1598
48
      }
1599
282
      zval tmp;
1600
282
      ZVAL_COPY_VALUE(&tmp, slot);
1601
282
      ZVAL_UNDEF(slot);
1602
282
      zval_ptr_dtor(&tmp);
1603
282
      if (zobj->properties) {
1604
105
        HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
1605
105
      }
1606
282
      return;
1607
282
    }
1608
81
    if (UNEXPECTED(Z_PROP_FLAG_P(slot) & IS_PROP_UNINIT)) {
1609
66
      if (UNEXPECTED(zend_lazy_object_must_init(zobj) && (Z_PROP_FLAG_P(slot) & IS_PROP_LAZY))) {
1610
12
        zobj = zend_lazy_object_init(zobj);
1611
12
        if (!zobj) {
1612
0
          return;
1613
0
        }
1614
12
        zend_std_unset_property(zobj, name, cache_slot);
1615
12
        return;
1616
12
      }
1617
1618
      /* Reset the IS_PROP_UNINIT flag, if it exists and bypass __unset(). */
1619
54
      Z_PROP_FLAG_P(slot) = 0;
1620
54
      return;
1621
66
    }
1622
270
  } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))
1623
237
   && EXPECTED(zobj->properties != NULL)) {
1624
162
    if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
1625
0
      if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
1626
0
        GC_DELREF(zobj->properties);
1627
0
      }
1628
0
      zobj->properties = zend_array_dup(zobj->properties);
1629
0
    }
1630
162
    if (EXPECTED(zend_hash_del(zobj->properties, name) != FAILURE)) {
1631
99
      return;
1632
99
    }
1633
162
  } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
1634
18
    zend_throw_error(NULL, "Cannot unset hooked property %s::$%s",
1635
18
      ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1636
18
    return;
1637
90
  } else if (UNEXPECTED(EG(exception))) {
1638
3
    return;
1639
3
  }
1640
1641
  /* For initialized lazy proxies: if the real instance's __unset guard
1642
   * is already set, we are inside a recursive call from the real
1643
   * instance's __unset. Forward directly to avoid double invocation. */
1644
165
  if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
1645
165
      && zend_lazy_object_initialized(zobj))) {
1646
6
    zend_object *instance = zend_lazy_object_get_instance(zobj);
1647
6
    if (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS) {
1648
6
      uint32_t *instance_guard = zend_get_property_guard(instance, name);
1649
6
      if ((*instance_guard) & IN_UNSET) {
1650
3
        zend_std_unset_property(instance, name, cache_slot);
1651
3
        return;
1652
3
      }
1653
6
    }
1654
6
  }
1655
1656
  /* magic unset */
1657
162
  if (zobj->ce->__unset) {
1658
93
    if (!guard) {
1659
81
      guard = zend_get_property_guard(zobj, name);
1660
81
    }
1661
93
    if (!((*guard) & IN_UNSET)) {
1662
      /* have unsetter - try with it! */
1663
60
      GC_ADDREF(zobj);
1664
60
      (*guard) |= IN_UNSET; /* prevent circular unsetting */
1665
60
      zend_std_call_unsetter(zobj, name);
1666
60
      (*guard) &= ~IN_UNSET;
1667
60
      OBJ_RELEASE(zobj);
1668
60
      return;
1669
60
    } else if (UNEXPECTED(IS_WRONG_PROPERTY_OFFSET(property_offset))) {
1670
      /* Trigger the correct error */
1671
6
      zend_wrong_offset(zobj->ce, name);
1672
6
      ZEND_ASSERT(EG(exception));
1673
6
      return;
1674
27
    } else {
1675
      /* Nothing to do: The property already does not exist. */
1676
27
    }
1677
93
  }
1678
1679
96
  if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
1680
24
    zobj = zend_lazy_object_init(zobj);
1681
24
    if (!zobj) {
1682
0
      return;
1683
0
    }
1684
1685
24
    if (UNEXPECTED(guard && zobj->ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
1686
9
      guard = zend_get_property_guard(zobj, name);
1687
9
      if (!((*guard) & IN_UNSET)) {
1688
6
        (*guard) |= IN_UNSET;
1689
6
        zend_std_unset_property(zobj, name, cache_slot);
1690
6
        (*guard) &= ~IN_UNSET;
1691
6
        return;
1692
6
      }
1693
9
    }
1694
1695
18
    zend_std_unset_property(zobj, name, cache_slot);
1696
18
    return;
1697
24
  }
1698
96
}
1699
/* }}} */
1700
1701
ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{ */
1702
90
{
1703
90
  const zend_class_entry *ce = object->ce;
1704
90
  zval tmp_offset;
1705
1706
90
  zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
1707
90
  if (EXPECTED(funcs)) {
1708
87
    ZVAL_COPY_DEREF(&tmp_offset, offset);
1709
87
    GC_ADDREF(object);
1710
87
    zend_call_known_instance_method_with_1_params(funcs->zf_offsetunset, object, NULL, &tmp_offset);
1711
87
    OBJ_RELEASE(object);
1712
87
    zval_ptr_dtor(&tmp_offset);
1713
87
  } else {
1714
3
      zend_bad_array_access(ce);
1715
3
  }
1716
90
}
1717
/* }}} */
1718
1719
static zend_never_inline zend_function *zend_get_parent_private_method(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *function_name) /* {{{ */
1720
39
{
1721
39
  zval *func;
1722
39
  zend_function *fbc;
1723
1724
39
  if (scope != ce && scope && is_derived_class(ce, scope)) {
1725
30
    func = zend_hash_find(&scope->function_table, function_name);
1726
30
    if (func != NULL) {
1727
30
      fbc = Z_FUNC_P(func);
1728
30
      if ((fbc->common.fn_flags & ZEND_ACC_PRIVATE)
1729
30
       && fbc->common.scope == scope) {
1730
24
        return fbc;
1731
24
      }
1732
30
    }
1733
30
  }
1734
15
  return NULL;
1735
39
}
1736
/* }}} */
1737
1738
/* Ensures that we're allowed to call a protected method.
1739
 */
1740
ZEND_API bool zend_check_protected(const zend_class_entry *ce, const zend_class_entry *scope) /* {{{ */
1741
433
{
1742
433
  const zend_class_entry *fbc_scope = ce;
1743
1744
  /* Is the context that's calling the function, the same as one of
1745
   * the function's parents?
1746
   */
1747
836
  while (fbc_scope) {
1748
490
    if (fbc_scope==scope) {
1749
87
      return 1;
1750
87
    }
1751
403
    fbc_scope = fbc_scope->parent;
1752
403
  }
1753
1754
  /* Is the function's scope the same as our current object context,
1755
   * or any of the parents of our context?
1756
   */
1757
584
  while (scope) {
1758
413
    if (scope==ce) {
1759
175
      return 1;
1760
175
    }
1761
238
    scope = scope->parent;
1762
238
  }
1763
171
  return 0;
1764
346
}
1765
/* }}} */
1766
1767
ZEND_API ZEND_ATTRIBUTE_NONNULL zend_function *zend_get_call_trampoline_func(
1768
  const zend_function *fbc, zend_string *method_name) /* {{{ */
1769
1.66k
{
1770
1.66k
  size_t mname_len;
1771
1.66k
  zend_op_array *func;
1772
  /* We use non-NULL value to avoid useless run_time_cache allocation.
1773
   * The low bit must be zero, to not be interpreted as a MAP_PTR offset.
1774
   */
1775
1.66k
  static const void *dummy = (void*)(intptr_t)2;
1776
1777
1.66k
  if (EXPECTED(EG(trampoline).common.function_name == NULL)) {
1778
1.66k
    func = &EG(trampoline).op_array;
1779
1.66k
  } else {
1780
6
    func = ecalloc(1, sizeof(zend_op_array));
1781
6
  }
1782
1783
1.66k
  func->type = ZEND_USER_FUNCTION;
1784
1.66k
  func->arg_flags[0] = 0;
1785
1.66k
  func->arg_flags[1] = 0;
1786
1.66k
  func->arg_flags[2] = 0;
1787
1.66k
  func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
1788
1.66k
    | ZEND_ACC_PUBLIC
1789
1.66k
    | ZEND_ACC_VARIADIC
1790
1.66k
    | (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD|ZEND_ACC_STATIC));
1791
1.66k
  func->fn_flags2 = 0;
1792
  /* Attributes outlive the trampoline because they are created by the compiler. */
1793
1.66k
  func->attributes = fbc->common.attributes;
1794
1.66k
  func->opcodes = &EG(call_trampoline_op);
1795
1.66k
  ZEND_MAP_PTR_INIT(func->run_time_cache, (void**)dummy);
1796
1.66k
  func->scope = fbc->common.scope;
1797
  /* reserve space for arguments, local and temporary variables */
1798
  /* EG(trampoline) is reused from other places, like FFI (e.g. zend_ffi_cdata_get_closure()) where
1799
   * it is used as an internal function. It may set fields that don't belong to common, thus
1800
   * modifying zend_op_array specific data, most significantly last_var. We need to reset this
1801
   * value so that it doesn't contain garbage when the engine allocates space for the next stack
1802
   * frame. This didn't cause any issues until now due to "lucky" structure layout. */
1803
1.66k
  func->last_var = 0;
1804
1.66k
  uint32_t min_T = 2 + ZEND_OBSERVER_ENABLED;
1805
1.66k
  func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, min_T) : min_T;
1806
1.66k
  func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : ZSTR_EMPTY_ALLOC();
1807
1.66k
  func->line_start = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_start : 0;
1808
1.66k
  func->line_end = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_end : 0;
1809
1810
  //??? keep compatibility for "\0" characters
1811
  //??? see: Zend/tests/bug46238.phpt
1812
1.66k
  if (UNEXPECTED((mname_len = strlen(ZSTR_VAL(method_name))) != ZSTR_LEN(method_name))) {
1813
15
    func->function_name = zend_string_init(ZSTR_VAL(method_name), mname_len, 0);
1814
1.65k
  } else {
1815
1.65k
    func->function_name = zend_string_copy(method_name);
1816
1.65k
  }
1817
1818
1.66k
  func->prototype = NULL;
1819
1.66k
  func->prop_info = NULL;
1820
1.66k
  func->num_args = 0;
1821
1.66k
  func->required_num_args = 0;
1822
1.66k
  func->arg_info = zend_call_trampoline_arginfo;
1823
1824
1.66k
  return (zend_function*)func;
1825
1.66k
}
1826
/* }}} */
1827
1828
static ZEND_FUNCTION(zend_parent_hook_get_trampoline)
1829
192
{
1830
192
  zend_object *obj = Z_PTR_P(ZEND_THIS);
1831
192
  zend_string *prop_name = EX(func)->internal_function.reserved[0];
1832
1833
192
  if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) {
1834
9
    zend_wrong_parameters_none_error();
1835
9
    goto clean;
1836
9
  }
1837
1838
183
  zval rv;
1839
183
  const zval *retval = obj->handlers->read_property(obj, prop_name, BP_VAR_R, NULL, &rv);
1840
183
  if (retval == &rv) {
1841
0
    RETVAL_COPY_VALUE(retval);
1842
183
  } else {
1843
183
    RETVAL_COPY(retval);
1844
183
  }
1845
1846
192
clean:
1847
192
  zend_string_release(EX(func)->common.function_name);
1848
192
  zend_free_trampoline(EX(func));
1849
192
  EX(func) = NULL;
1850
192
}
1851
1852
static ZEND_FUNCTION(zend_parent_hook_set_trampoline)
1853
21
{
1854
21
  zend_object *obj = Z_PTR_P(ZEND_THIS);
1855
21
  zend_string *prop_name = EX(func)->internal_function.reserved[0];
1856
1857
21
  zval *value;
1858
1859
54
  ZEND_PARSE_PARAMETERS_START(1, 1)
1860
54
    Z_PARAM_ZVAL(value)
1861
48
  ZEND_PARSE_PARAMETERS_END_EX(goto clean);
1862
1863
12
  RETVAL_COPY(obj->handlers->write_property(obj, prop_name, value, NULL));
1864
1865
21
clean:
1866
21
  zend_string_release(EX(func)->common.function_name);
1867
21
  zend_free_trampoline(EX(func));
1868
21
  EX(func) = NULL;
1869
21
}
1870
1871
ZEND_API zend_function *zend_get_property_hook_trampoline(
1872
  const zend_property_info *prop_info,
1873
  zend_property_hook_kind kind, zend_string *prop_name)
1874
216
{
1875
216
  zend_function *func;
1876
216
  if (EXPECTED(EG(trampoline).common.function_name == NULL)) {
1877
216
    func = &EG(trampoline);
1878
216
  } else {
1879
0
    func = (zend_function *)(uintptr_t)ecalloc(1, sizeof(zend_internal_function));
1880
0
  }
1881
216
  func->type = ZEND_INTERNAL_FUNCTION;
1882
  /* This trampoline does not use the call_trampoline_op, so it won't reuse the call frame,
1883
   * which means we don't even need to reserve a temporary for observers. */
1884
216
  func->common.T = 0;
1885
216
  func->common.arg_flags[0] = 0;
1886
216
  func->common.arg_flags[1] = 0;
1887
216
  func->common.arg_flags[2] = 0;
1888
216
  func->common.fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE;
1889
216
  func->common.fn_flags2 = 0;
1890
216
  func->common.function_name = zend_string_concat3(
1891
216
    "$", 1, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name),
1892
216
    kind == ZEND_PROPERTY_HOOK_GET ? "::get" : "::set", 5);
1893
  /* set to 0 to avoid arg_info[] allocation, because all values are passed by value anyway */
1894
216
  uint32_t args = kind == ZEND_PROPERTY_HOOK_GET ? 0 : 1;
1895
216
  func->common.num_args = args;
1896
216
  func->common.required_num_args = args;
1897
216
  func->common.scope = prop_info->ce;
1898
216
  func->common.prototype = NULL;
1899
216
  func->common.prop_info = prop_info;
1900
216
  func->common.arg_info = zend_property_hook_arginfo;
1901
216
  func->internal_function.handler = kind == ZEND_PROPERTY_HOOK_GET
1902
216
    ? ZEND_FN(zend_parent_hook_get_trampoline)
1903
216
    : ZEND_FN(zend_parent_hook_set_trampoline);
1904
216
  func->internal_function.module = NULL;
1905
1906
216
  func->internal_function.reserved[0] = prop_name;
1907
216
  func->internal_function.reserved[1] = NULL;
1908
1909
216
  return func;
1910
216
}
1911
1912
ZEND_API ZEND_COLD zend_never_inline void zend_bad_method_call(const zend_function *fbc, const zend_string *method_name, const zend_class_entry *scope) /* {{{ */
1913
36
{
1914
36
  zend_throw_error(NULL, "Call to %s method %s::%s() from %s%s",
1915
36
    zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), ZSTR_VAL(method_name),
1916
36
    scope ? "scope " : "global scope",
1917
36
    scope ? ZSTR_VAL(scope->name) : ""
1918
36
  );
1919
36
}
1920
/* }}} */
1921
1922
ZEND_API ZEND_COLD zend_never_inline void zend_abstract_method_call(const zend_function *fbc) /* {{{ */
1923
21
{
1924
21
  zend_throw_error(NULL, "Cannot call abstract method %s::%s()",
1925
21
    ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
1926
21
}
1927
/* }}} */
1928
1929
ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key) /* {{{ */
1930
43.4k
{
1931
43.4k
  zend_object *zobj = *obj_ptr;
1932
43.4k
  zval *func;
1933
43.4k
  zend_function *fbc;
1934
43.4k
  zend_string *lc_method_name;
1935
43.4k
  ALLOCA_FLAG(use_heap);
1936
1937
43.4k
  if (EXPECTED(key != NULL)) {
1938
42.0k
    lc_method_name = Z_STR_P(key);
1939
#ifdef ZEND_ALLOCA_MAX_SIZE
1940
    use_heap = 0;
1941
#endif
1942
42.0k
  } else {
1943
1.40k
    ZSTR_ALLOCA_ALLOC(lc_method_name, ZSTR_LEN(method_name), use_heap);
1944
1.40k
    zend_str_tolower_copy(ZSTR_VAL(lc_method_name), ZSTR_VAL(method_name), ZSTR_LEN(method_name));
1945
1.40k
  }
1946
1947
43.4k
  if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
1948
1.58k
    if (UNEXPECTED(!key)) {
1949
998
      ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
1950
998
    }
1951
1.58k
    if (zobj->ce->__call) {
1952
1.19k
      return zend_get_call_trampoline_func(zobj->ce->__call, method_name);
1953
1.19k
    } else {
1954
389
      return NULL;
1955
389
    }
1956
1.58k
  }
1957
1958
41.8k
  fbc = Z_FUNC_P(func);
1959
1960
  /* Check access level */
1961
41.8k
  if (fbc->op_array.fn_flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
1962
285
    const zend_class_entry *scope = zend_get_executed_scope();
1963
1964
285
    if (fbc->common.scope != scope) {
1965
125
      if (fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
1966
39
        zend_function *updated_fbc = zend_get_parent_private_method(scope, zobj->ce, lc_method_name);
1967
1968
39
        if (EXPECTED(updated_fbc != NULL)) {
1969
24
          fbc = updated_fbc;
1970
24
          goto exit;
1971
24
        } else if (fbc->op_array.fn_flags & ZEND_ACC_PUBLIC) {
1972
12
          goto exit;
1973
12
        }
1974
39
      }
1975
89
      if (UNEXPECTED(fbc->op_array.fn_flags & ZEND_ACC_PRIVATE)
1976
56
       || UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), scope))) {
1977
52
        if (zobj->ce->__call) {
1978
34
          fbc = zend_get_call_trampoline_func(zobj->ce->__call, method_name);
1979
34
        } else {
1980
18
          zend_bad_method_call(fbc, method_name, scope);
1981
18
          fbc = NULL;
1982
18
        }
1983
52
      }
1984
89
    }
1985
285
  }
1986
1987
41.8k
exit:
1988
41.8k
  if (fbc && UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
1989
0
    zend_abstract_method_call(fbc);
1990
0
    fbc = NULL;
1991
0
  }
1992
41.8k
  if (UNEXPECTED(!key)) {
1993
404
    ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
1994
404
  }
1995
41.8k
  return fbc;
1996
41.8k
}
1997
/* }}} */
1998
1999
static zend_always_inline zend_function *get_static_method_fallback(
2000
    const zend_class_entry *ce, zend_string *function_name)
2001
531
{
2002
531
  zend_object *object;
2003
531
  if (ce->__call &&
2004
303
    (object = zend_get_this_object(EG(current_execute_data))) != NULL &&
2005
138
    instanceof_function(object->ce, ce)) {
2006
    /* Call the top-level defined __call().
2007
     * see: tests/classes/__call_004.phpt  */
2008
2009
132
    ZEND_ASSERT(object->ce->__call);
2010
132
    return zend_get_call_trampoline_func(object->ce->__call, function_name);
2011
399
  } else if (ce->__callstatic) {
2012
303
    return zend_get_call_trampoline_func(ce->__callstatic, function_name);
2013
303
  } else {
2014
96
    return NULL;
2015
96
  }
2016
531
}
2017
2018
ZEND_API zend_function *zend_std_get_static_method(const zend_class_entry *ce, zend_string *function_name, const zval *key) /* {{{ */
2019
3.07k
{
2020
3.07k
  zend_string *lc_function_name;
2021
3.07k
  if (EXPECTED(key != NULL)) {
2022
2.74k
    lc_function_name = Z_STR_P(key);
2023
2.74k
  } else {
2024
336
    lc_function_name = zend_string_tolower(function_name);
2025
336
  }
2026
2027
3.07k
  zend_function *fbc;
2028
3.07k
  zval *func = zend_hash_find(&ce->function_table, lc_function_name);
2029
3.07k
  if (EXPECTED(func)) {
2030
2.56k
    fbc = Z_FUNC_P(func);
2031
2.56k
    if (!(fbc->common.fn_flags & ZEND_ACC_PUBLIC)) {
2032
93
      const zend_class_entry *scope = zend_get_executed_scope();
2033
93
      ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_PUBLIC));
2034
93
      if (!zend_check_method_accessible(fbc, scope)) {
2035
24
        zend_function *fallback_fbc = get_static_method_fallback(ce, function_name);
2036
24
        if (!fallback_fbc) {
2037
12
          zend_bad_method_call(fbc, function_name, scope);
2038
12
        }
2039
24
        fbc = fallback_fbc;
2040
24
      }
2041
93
    }
2042
2.56k
  } else {
2043
507
    fbc = get_static_method_fallback(ce, function_name);
2044
507
  }
2045
2046
3.07k
  if (UNEXPECTED(!key)) {
2047
336
    zend_string_release_ex(lc_function_name, 0);
2048
336
  }
2049
2050
3.07k
  if (EXPECTED(fbc)) {
2051
2.98k
    if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
2052
18
      zend_abstract_method_call(fbc);
2053
18
      goto fail;
2054
2.96k
    } else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
2055
12
      zend_error(E_DEPRECATED,
2056
12
        "Calling static trait method %s::%s is deprecated, "
2057
12
        "it should only be called on a class using the trait",
2058
12
        ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2059
12
      if (EG(exception)) {
2060
0
        goto fail;
2061
0
      }
2062
12
    }
2063
2.98k
  }
2064
2065
3.05k
  return fbc;
2066
2067
18
 fail:
2068
18
  if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
2069
3
    zend_string_release_ex(fbc->common.function_name, 0);
2070
3
    zend_free_trampoline(fbc);
2071
3
  }
2072
2073
18
  return NULL;
2074
3.07k
}
2075
/* }}} */
2076
2077
ZEND_API void zend_class_init_statics(zend_class_entry *class_type) /* {{{ */
2078
798
{
2079
798
  zval *p;
2080
2081
798
  if (class_type->default_static_members_count && !CE_STATIC_MEMBERS(class_type)) {
2082
747
    if (class_type->parent) {
2083
69
      zend_class_init_statics(class_type->parent);
2084
69
    }
2085
2086
747
    ZEND_MAP_PTR_SET(class_type->static_members_table, emalloc(sizeof(zval) * class_type->default_static_members_count));
2087
2.13k
    for (uint32_t i = 0; i < class_type->default_static_members_count; i++) {
2088
1.38k
      p = &class_type->default_static_members_table[i];
2089
1.38k
      if (Z_TYPE_P(p) == IS_INDIRECT) {
2090
72
        zval *q = &CE_STATIC_MEMBERS(class_type->parent)[i];
2091
72
        ZVAL_DEINDIRECT(q);
2092
72
        ZVAL_INDIRECT(&CE_STATIC_MEMBERS(class_type)[i], q);
2093
1.31k
      } else {
2094
1.31k
        ZVAL_COPY_OR_DUP(&CE_STATIC_MEMBERS(class_type)[i], p);
2095
1.31k
      }
2096
1.38k
    }
2097
747
  }
2098
798
} /* }}} */
2099
2100
ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend_string *property_name, int type, zend_property_info **property_info_ptr) /* {{{ */
2101
1.96k
{
2102
1.96k
  zval *ret;
2103
1.96k
  zend_property_info *property_info = zend_hash_find_ptr(&ce->properties_info, property_name);
2104
1.96k
  *property_info_ptr = property_info;
2105
2106
1.96k
  if (UNEXPECTED(property_info == NULL)) {
2107
165
    goto undeclared_property;
2108
165
  }
2109
2110
1.80k
  if (!(property_info->flags & ZEND_ACC_PUBLIC)) {
2111
530
    const zend_class_entry *scope = get_fake_or_executed_scope();
2112
530
    if (property_info->ce != scope) {
2113
93
      if (UNEXPECTED(property_info->flags & ZEND_ACC_PRIVATE)
2114
63
       || UNEXPECTED(!is_protected_compatible_scope(property_info->prototype->ce, scope))) {
2115
63
        if (type != BP_VAR_IS) {
2116
12
          zend_bad_property_access(property_info, ce, property_name);
2117
12
        }
2118
63
        return NULL;
2119
63
      }
2120
93
    }
2121
530
  }
2122
2123
1.73k
  if (UNEXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0)) {
2124
181
undeclared_property:
2125
181
    if (type != BP_VAR_IS) {
2126
127
      zend_throw_error(NULL, "Access to undeclared static property %s::$%s", ZSTR_VAL(ce->name), ZSTR_VAL(property_name));
2127
127
    }
2128
181
    return NULL;
2129
16
  }
2130
2131
1.72k
  if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
2132
165
    if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
2133
12
      return NULL;
2134
12
    }
2135
165
  }
2136
2137
  /* Ensure static properties are initialized. */
2138
1.70k
  if (UNEXPECTED(CE_STATIC_MEMBERS(ce) == NULL)) {
2139
657
    zend_class_init_statics(ce);
2140
657
  }
2141
2142
1.70k
  ret = CE_STATIC_MEMBERS(ce) + property_info->offset;
2143
1.70k
  ZVAL_DEINDIRECT(ret);
2144
2145
1.70k
  if (UNEXPECTED((type == BP_VAR_R || type == BP_VAR_RW)
2146
1.70k
        && Z_TYPE_P(ret) == IS_UNDEF && ZEND_TYPE_IS_SET(property_info->type))) {
2147
9
    zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization",
2148
9
      ZSTR_VAL(property_info->ce->name), ZSTR_VAL(property_name));
2149
9
    return NULL;
2150
9
  }
2151
2152
1.70k
  if (UNEXPECTED(ce->ce_flags & ZEND_ACC_TRAIT)) {
2153
48
    zend_error(E_DEPRECATED,
2154
48
      "Accessing static trait property %s::$%s is deprecated, "
2155
48
      "it should only be accessed on a class using the trait",
2156
48
      ZSTR_VAL(property_info->ce->name), ZSTR_VAL(property_name));
2157
48
  }
2158
2159
1.70k
  return ret;
2160
1.70k
}
2161
/* }}} */
2162
2163
ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, int type) /* {{{ */
2164
6
{
2165
6
  zend_property_info *prop_info;
2166
6
  return zend_std_get_static_property_with_info(ce, property_name, type, &prop_info);
2167
6
}
2168
2169
ZEND_API ZEND_COLD bool zend_std_unset_static_property(const zend_class_entry *ce, const zend_string *property_name) /* {{{ */
2170
6
{
2171
6
  zend_throw_error(NULL, "Attempt to unset static property %s::$%s", ZSTR_VAL(ce->name), ZSTR_VAL(property_name));
2172
6
  return 0;
2173
6
}
2174
/* }}} */
2175
2176
static ZEND_COLD zend_never_inline void zend_bad_constructor_call(const zend_function *constructor, const zend_class_entry *scope) /* {{{ */
2177
23
{
2178
23
  if (scope) {
2179
6
    zend_throw_error(NULL, "Call to %s %s::__construct() from scope %s",
2180
6
      zend_visibility_string(constructor->common.fn_flags),
2181
6
      ZSTR_VAL(constructor->common.scope->name),
2182
6
      ZSTR_VAL(scope->name)
2183
6
    );
2184
17
  } else {
2185
17
    zend_throw_error(NULL, "Call to %s %s::__construct() from global scope",
2186
17
      zend_visibility_string(constructor->common.fn_flags),
2187
17
      ZSTR_VAL(constructor->common.scope->name)
2188
17
    );
2189
17
  }
2190
23
}
2191
/* }}} */
2192
2193
ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */
2194
220k
{
2195
220k
  zend_function *constructor = zobj->ce->constructor;
2196
2197
220k
  if (constructor) {
2198
180k
    if (UNEXPECTED(!(constructor->common.fn_flags & ZEND_ACC_PUBLIC))) {
2199
50
      const zend_class_entry *scope = get_fake_or_executed_scope();
2200
50
      ZEND_ASSERT(!(constructor->common.fn_flags & ZEND_ACC_PUBLIC));
2201
50
      if (!zend_check_method_accessible(constructor, scope)) {
2202
23
        zend_bad_constructor_call(constructor, scope);
2203
23
        zend_object_store_ctor_failed(zobj);
2204
23
        constructor = NULL;
2205
23
      }
2206
50
    }
2207
180k
  }
2208
2209
220k
  return constructor;
2210
220k
}
2211
/* }}} */
2212
2213
ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
2214
459
{
2215
459
  zend_object *zobj1, *zobj2;
2216
2217
459
  if (zend_objects_check_stack_limit()) {
2218
0
    zend_throw_error(NULL, "Maximum call stack size reached during object comparison");
2219
0
    return ZEND_UNCOMPARABLE;
2220
0
  }
2221
2222
459
  if (Z_TYPE_P(o1) != Z_TYPE_P(o2)) {
2223
    /* Object and non-object */
2224
354
    zval *object;
2225
354
    zval *value;
2226
354
    zval casted;
2227
354
    bool object_lhs;
2228
354
    if (Z_TYPE_P(o1) == IS_OBJECT) {
2229
303
      object = o1;
2230
303
      value = o2;
2231
303
      object_lhs = true;
2232
303
    } else {
2233
51
      object = o2;
2234
51
      value = o1;
2235
51
      object_lhs = false;
2236
51
    }
2237
354
    ZEND_ASSERT(Z_TYPE_P(value) != IS_OBJECT);
2238
354
    uint8_t target_type = Z_TYPE_P(value);
2239
    /* Should be handled in zend_compare(). */
2240
354
    ZEND_ASSERT(target_type != IS_FALSE && target_type != IS_TRUE);
2241
354
    if (Z_OBJ_HT_P(object)->cast_object(Z_OBJ_P(object), &casted, target_type) == FAILURE) {
2242
      // TODO: Less crazy.
2243
324
      if (target_type == IS_LONG || target_type == IS_DOUBLE) {
2244
228
        zend_error(E_NOTICE, "Object of class %s could not be converted to %s",
2245
228
               ZSTR_VAL(Z_OBJCE_P(object)->name), zend_get_type_by_const(target_type));
2246
228
        if (target_type == IS_LONG) {
2247
204
          ZVAL_LONG(&casted, 1);
2248
204
        } else {
2249
24
          ZVAL_DOUBLE(&casted, 1.0);
2250
24
        }
2251
228
      } else {
2252
96
        return object_lhs ? 1 : -1;
2253
96
      }
2254
324
    }
2255
258
    int ret = object_lhs ? zend_compare(&casted, value) : zend_compare(value, &casted);
2256
258
    zval_ptr_dtor(&casted);
2257
258
    return ret;
2258
354
  }
2259
2260
105
  zobj1 = Z_OBJ_P(o1);
2261
105
  zobj2 = Z_OBJ_P(o2);
2262
2263
105
  if (zobj1 == zobj2) {
2264
0
    return 0; /* the same object */
2265
0
  }
2266
105
  if (zobj1->ce != zobj2->ce) {
2267
12
    return ZEND_UNCOMPARABLE; /* different classes */
2268
12
  }
2269
93
  if (!zobj1->properties && !zobj2->properties
2270
78
      && !zend_object_is_lazy(zobj1) && !zend_object_is_lazy(zobj2)) {
2271
66
    zend_property_info *info;
2272
66
    int i;
2273
2274
66
    if (!zobj1->ce->default_properties_count) {
2275
30
      return 0;
2276
30
    }
2277
2278
    /* It's enough to protect only one of the objects.
2279
     * The second one may be referenced from the first and this may cause
2280
     * false recursion detection.
2281
     */
2282
    /* use bitwise OR to make only one conditional jump */
2283
36
    if (UNEXPECTED(Z_IS_RECURSIVE_P(o1))) {
2284
3
      zend_throw_error(NULL, "Nesting level too deep - recursive dependency?");
2285
3
      return ZEND_UNCOMPARABLE;
2286
3
    }
2287
33
    Z_PROTECT_RECURSION_P(o1);
2288
2289
33
    GC_ADDREF(zobj1);
2290
33
    GC_ADDREF(zobj2);
2291
33
    int ret;
2292
2293
51
    for (i = 0; i < zobj1->ce->default_properties_count; i++) {
2294
45
      zval *p1, *p2;
2295
2296
45
      info = zobj1->ce->properties_info_table[i];
2297
2298
45
      if (!info) {
2299
6
        continue;
2300
6
      }
2301
2302
39
      p1 = OBJ_PROP(zobj1, info->offset);
2303
39
      p2 = OBJ_PROP(zobj2, info->offset);
2304
2305
39
      if (Z_TYPE_P(p1) != IS_UNDEF) {
2306
39
        if (Z_TYPE_P(p2) != IS_UNDEF) {
2307
39
          ret = zend_compare(p1, p2);
2308
39
          if (ret != 0) {
2309
27
            Z_UNPROTECT_RECURSION_P(o1);
2310
27
            goto done;
2311
27
          }
2312
39
        } else {
2313
0
          Z_UNPROTECT_RECURSION_P(o1);
2314
0
          ret = 1;
2315
0
          goto done;
2316
0
        }
2317
39
      } else {
2318
0
        if (Z_TYPE_P(p2) != IS_UNDEF) {
2319
0
          Z_UNPROTECT_RECURSION_P(o1);
2320
0
          ret = 1;
2321
0
          goto done;
2322
0
        }
2323
0
      }
2324
39
    }
2325
2326
6
    Z_UNPROTECT_RECURSION_P(o1);
2327
6
    ret = 0;
2328
2329
33
done:
2330
33
    OBJ_RELEASE(zobj1);
2331
33
    OBJ_RELEASE(zobj2);
2332
2333
33
    return ret;
2334
27
  } else {
2335
27
    GC_ADDREF(zobj1);
2336
27
    GC_ADDREF(zobj2);
2337
2338
27
    int ret = zend_compare_symbol_tables(
2339
27
        zend_std_get_properties_ex(zobj1),
2340
27
        zend_std_get_properties_ex(zobj2));
2341
2342
27
    OBJ_RELEASE(zobj1);
2343
27
    OBJ_RELEASE(zobj2);
2344
2345
27
    return ret;
2346
27
  }
2347
93
}
2348
/* }}} */
2349
2350
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
2351
344
{
2352
344
  return ZEND_UNCOMPARABLE;
2353
344
}
2354
2355
// todo: make zend_std_has_property return bool as well
2356
ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) /* {{{ */
2357
597
{
2358
597
  bool result;
2359
597
  zval *value = NULL;
2360
597
  uintptr_t property_offset;
2361
597
  const zend_property_info *prop_info = NULL;
2362
2363
597
  property_offset = zend_get_property_offset(zobj->ce, name, 1, cache_slot, &prop_info);
2364
2365
597
  if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
2366
138
try_again:
2367
138
    value = OBJ_PROP(zobj, property_offset);
2368
138
    if (Z_TYPE_P(value) != IS_UNDEF) {
2369
75
      goto found;
2370
75
    }
2371
63
    if (UNEXPECTED(Z_PROP_FLAG_P(value) & IS_PROP_UNINIT)) {
2372
      /* Skip __isset() for uninitialized typed properties */
2373
39
      goto lazy_init;
2374
39
    }
2375
462
  } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
2376
402
    if (EXPECTED(zobj->properties != NULL)) {
2377
156
      if (!IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(property_offset)) {
2378
9
        uintptr_t idx = ZEND_DECODE_DYN_PROP_OFFSET(property_offset);
2379
2380
9
        if (EXPECTED(idx < zobj->properties->nNumUsed * sizeof(Bucket))) {
2381
9
          Bucket *p = (Bucket*)((char*)zobj->properties->arData + idx);
2382
2383
9
          if (EXPECTED(p->key == name) ||
2384
3
                (EXPECTED(p->h == ZSTR_H(name)) &&
2385
3
                 EXPECTED(p->key != NULL) &&
2386
6
                 EXPECTED(zend_string_equal_content(p->key, name)))) {
2387
6
            value = &p->val;
2388
6
            goto found;
2389
6
          }
2390
9
        }
2391
3
        CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_DYNAMIC_PROPERTY_OFFSET);
2392
3
      }
2393
150
      value = zend_hash_find(zobj->properties, name);
2394
150
      if (value) {
2395
123
        if (cache_slot) {
2396
27
          uintptr_t idx = (char*)value - (char*)zobj->properties->arData;
2397
27
          CACHE_PTR_EX(cache_slot + 1, (void*)ZEND_ENCODE_DYN_PROP_OFFSET(idx));
2398
27
        }
2399
204
found:
2400
204
        if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) {
2401
9
          result = zend_is_true(value);
2402
195
        } else if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) {
2403
168
          ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET);
2404
168
          ZVAL_DEREF(value);
2405
168
          result = (Z_TYPE_P(value) != IS_NULL);
2406
168
        } else {
2407
27
          ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS);
2408
27
          result = true;
2409
27
        }
2410
204
        goto exit;
2411
204
      }
2412
150
    }
2413
402
  } else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
2414
45
    zend_function *get = prop_info->hooks[ZEND_PROPERTY_HOOK_GET];
2415
2416
45
    if (has_set_exists == ZEND_PROPERTY_EXISTS) {
2417
0
      if (prop_info->flags & ZEND_ACC_VIRTUAL) {
2418
0
        return true;
2419
0
      }
2420
0
      property_offset = prop_info->offset;
2421
0
      goto try_again;
2422
0
    }
2423
2424
45
    if (!get) {
2425
3
      if (prop_info->flags & ZEND_ACC_VIRTUAL) {
2426
3
        zend_throw_error(NULL, "Cannot read from set-only virtual property %s::$%s",
2427
3
          ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
2428
3
        return 0;
2429
3
      } else {
2430
0
        property_offset = prop_info->offset;
2431
0
        goto try_again;
2432
0
      }
2433
3
    }
2434
2435
42
    zval rv;
2436
42
    if (!zend_call_get_hook(prop_info, name, get, zobj, &rv)) {
2437
3
      if (EG(exception)) {
2438
0
        return 0;
2439
0
      }
2440
3
      property_offset = prop_info->offset;
2441
3
      goto try_again;
2442
3
    }
2443
2444
39
    if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) {
2445
9
      result = zend_is_true(&rv);
2446
30
    } else {
2447
30
      ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET);
2448
30
      result = Z_TYPE(rv) != IS_NULL
2449
21
        && (Z_TYPE(rv) != IS_REFERENCE || Z_TYPE_P(Z_REFVAL(rv)) != IS_NULL);
2450
30
    }
2451
39
    zval_ptr_dtor(&rv);
2452
39
    return result;
2453
39
  } else if (UNEXPECTED(EG(exception))) {
2454
0
    result = false;
2455
0
    goto exit;
2456
0
  }
2457
2458
  /* For initialized lazy proxies: if the real instance's __isset guard
2459
   * is already set, we are inside a recursive call from the real
2460
   * instance's __isset. Forward directly to avoid double invocation. */
2461
312
  if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
2462
312
      && zend_lazy_object_initialized(zobj))) {
2463
6
    zend_object *instance = zend_lazy_object_get_instance(zobj);
2464
6
    if (instance->ce->ce_flags & ZEND_ACC_USE_GUARDS) {
2465
6
      uint32_t *instance_guard = zend_get_property_guard(instance, name);
2466
6
      if ((*instance_guard) & IN_ISSET) {
2467
6
        return zend_std_has_property(instance, name, has_set_exists, cache_slot);
2468
6
      }
2469
6
    }
2470
6
  }
2471
2472
306
  if (!zobj->ce->__isset) {
2473
93
    goto lazy_init;
2474
93
  }
2475
2476
213
  result = false;
2477
213
  if (has_set_exists != ZEND_PROPERTY_EXISTS) {
2478
213
    uint32_t *guard = zend_get_property_guard(zobj, name);
2479
2480
213
    if (!((*guard) & IN_ISSET)) {
2481
171
      zval rv;
2482
2483
      /* have issetter - try with it! */
2484
171
      GC_ADDREF(zobj);
2485
171
      (*guard) |= IN_ISSET; /* prevent circular getting */
2486
171
      zend_std_call_issetter(zobj, name, &rv);
2487
171
      result = zend_is_true(&rv);
2488
171
      zval_ptr_dtor(&rv);
2489
171
      if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY && result) {
2490
18
        if (EXPECTED(!EG(exception)) && zobj->ce->__get && !((*guard) & IN_GET)) {
2491
15
          (*guard) |= IN_GET;
2492
15
          zend_std_call_getter(zobj, name, &rv);
2493
15
          (*guard) &= ~IN_GET;
2494
15
          result = i_zend_is_true(&rv);
2495
15
          zval_ptr_dtor(&rv);
2496
15
        } else {
2497
3
          result = false;
2498
3
        }
2499
18
      }
2500
171
      (*guard) &= ~IN_ISSET;
2501
171
      OBJ_RELEASE(zobj);
2502
171
    } else {
2503
42
      goto lazy_init;
2504
42
    }
2505
213
  }
2506
2507
540
exit:
2508
540
  return result;
2509
2510
174
lazy_init:
2511
174
  if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
2512
9
    if (!value || (Z_PROP_FLAG_P(value) & IS_PROP_LAZY)) {
2513
9
      zobj = zend_lazy_object_init(zobj);
2514
9
      if (!zobj) {
2515
0
        result = false;
2516
0
        goto exit;
2517
0
      }
2518
2519
9
      if (UNEXPECTED(zobj->ce->__isset)) {
2520
3
        uint32_t *guard = zend_get_property_guard(zobj, name);
2521
3
        if (!((*guard) & IN_ISSET)) {
2522
3
          (*guard) |= IN_ISSET;
2523
3
          result = zend_std_has_property(zobj, name, has_set_exists, cache_slot);
2524
3
          (*guard) &= ~IN_ISSET;
2525
3
          return result;
2526
3
        }
2527
3
      }
2528
2529
6
      return zend_std_has_property(zobj, name, has_set_exists, cache_slot);
2530
9
    }
2531
9
  }
2532
2533
165
  result = false;
2534
165
  goto exit;
2535
174
}
2536
/* }}} */
2537
2538
ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj) /* {{{ */
2539
6.76k
{
2540
6.76k
  return zend_string_copy(zobj->ce->name);
2541
6.76k
}
2542
/* }}} */
2543
2544
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */
2545
3.51k
{
2546
3.51k
  switch (type) {
2547
2.78k
    case IS_STRING: {
2548
2.78k
      const zend_class_entry *ce = readobj->ce;
2549
2.78k
      if (ce->__tostring) {
2550
2.64k
        zval retval;
2551
2.64k
        GC_ADDREF(readobj);
2552
2.64k
        zend_call_known_instance_method_with_0_params(ce->__tostring, readobj, &retval);
2553
2.64k
        zend_object_release(readobj);
2554
2.64k
        if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
2555
2.29k
is_string:
2556
2.29k
          ZVAL_COPY_VALUE(writeobj, &retval);
2557
2.29k
          return SUCCESS;
2558
2.29k
        } else if (Z_ISREF(retval)) {
2559
3
          zend_unwrap_reference(&retval);
2560
3
          goto is_string;
2561
3
        }
2562
351
        zval_ptr_dtor(&retval);
2563
351
        if (!EG(exception)) {
2564
0
          zend_throw_error(NULL, "Method %s::__toString() must return a string value", ZSTR_VAL(ce->name));
2565
0
        }
2566
351
      }
2567
486
      return FAILURE;
2568
2.78k
    }
2569
237
    case _IS_BOOL:
2570
237
      ZVAL_TRUE(writeobj);
2571
237
      return SUCCESS;
2572
499
    default:
2573
499
      return FAILURE;
2574
3.51k
  }
2575
3.51k
}
2576
/* }}} */
2577
2578
ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */
2579
153
{
2580
153
  zend_class_entry *ce = obj->ce;
2581
153
  const zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
2582
2583
153
  if (func == NULL) {
2584
15
    return FAILURE;
2585
15
  }
2586
138
  *fptr_ptr = Z_FUNC_P(func);
2587
138
  *ce_ptr = ce;
2588
138
  *obj_ptr = obj;
2589
2590
138
  return SUCCESS;
2591
153
}
2592
/* }}} */
2593
2594
6.72k
ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purpose purpose) {
2595
6.72k
  HashTable *ht;
2596
6.72k
  switch (purpose) {
2597
6.14k
    case ZEND_PROP_PURPOSE_DEBUG:
2598
6.14k
      if (obj->handlers->get_debug_info) {
2599
6.14k
        int is_temp;
2600
6.14k
        ht = obj->handlers->get_debug_info(obj, &is_temp);
2601
6.14k
        if (ht && !is_temp) {
2602
4.87k
          GC_TRY_ADDREF(ht);
2603
4.87k
        }
2604
6.14k
        return ht;
2605
6.14k
      }
2606
0
      ZEND_FALLTHROUGH;
2607
141
    case ZEND_PROP_PURPOSE_JSON:
2608
282
    case ZEND_PROP_PURPOSE_GET_OBJECT_VARS:
2609
378
    case ZEND_PROP_PURPOSE_VAR_EXPORT:
2610
378
      if (obj->ce->num_hooked_props) {
2611
249
        return zend_hooked_object_build_properties(obj);
2612
249
      }
2613
129
      ht = obj->handlers->get_properties(obj);
2614
129
      if (ht) {
2615
129
        GC_TRY_ADDREF(ht);
2616
129
      }
2617
129
      return ht;
2618
99
    case ZEND_PROP_PURPOSE_ARRAY_CAST:
2619
99
      ht = zend_get_properties_no_lazy_init(obj);
2620
99
      if (ht) {
2621
99
        GC_TRY_ADDREF(ht);
2622
99
      }
2623
99
      return ht;
2624
105
    case ZEND_PROP_PURPOSE_SERIALIZE: {
2625
105
      if (zend_object_is_lazy(obj)
2626
75
          && !zend_lazy_object_initialize_on_serialize(obj)) {
2627
21
        ht = zend_get_properties_no_lazy_init(obj);
2628
84
      } else {
2629
84
        ht = obj->handlers->get_properties(obj);
2630
84
      }
2631
105
      if (ht) {
2632
105
        GC_TRY_ADDREF(ht);
2633
105
      }
2634
105
      return ht;
2635
378
    }
2636
0
    default:
2637
0
      ZEND_UNREACHABLE();
2638
0
      return NULL;
2639
6.72k
  }
2640
6.72k
}
2641
2642
7.02k
ZEND_API HashTable *zend_get_properties_for(zval *obj, zend_prop_purpose purpose) {
2643
7.02k
  zend_object *zobj = Z_OBJ_P(obj);
2644
2645
7.02k
  if (zobj->handlers->get_properties_for) {
2646
333
    return zobj->handlers->get_properties_for(zobj, purpose);
2647
333
  }
2648
2649
6.69k
  return zend_std_get_properties_for(zobj, purpose);
2650
7.02k
}
2651
2652
ZEND_API const zend_object_handlers std_object_handlers = {
2653
  0,                    /* offset */
2654
2655
  zend_object_std_dtor,         /* free_obj */
2656
  zend_objects_destroy_object,      /* dtor_obj */
2657
  zend_objects_clone_obj,         /* clone_obj */
2658
  zend_objects_clone_obj_with,      /* clone_obj_with */
2659
2660
  zend_std_read_property,         /* read_property */
2661
  zend_std_write_property,        /* write_property */
2662
  zend_std_read_dimension,        /* read_dimension */
2663
  zend_std_write_dimension,       /* write_dimension */
2664
  zend_std_get_property_ptr_ptr,      /* get_property_ptr_ptr */
2665
  zend_std_has_property,          /* has_property */
2666
  zend_std_unset_property,        /* unset_property */
2667
  zend_std_has_dimension,         /* has_dimension */
2668
  zend_std_unset_dimension,       /* unset_dimension */
2669
  zend_std_get_properties,        /* get_properties */
2670
  zend_std_get_method,          /* get_method */
2671
  zend_std_get_constructor,       /* get_constructor */
2672
  zend_std_get_class_name,        /* get_class_name */
2673
  zend_std_cast_object_tostring,      /* cast_object */
2674
  NULL,                 /* count_elements */
2675
  zend_std_get_debug_info,        /* get_debug_info */
2676
  zend_std_get_closure,         /* get_closure */
2677
  zend_std_get_gc,            /* get_gc */
2678
  NULL,                 /* do_operation */
2679
  zend_std_compare_objects,       /* compare */
2680
  NULL,                 /* get_properties_for */
2681
};
2682
2683
2
void zend_object_handlers_startup(void) {
2684
2
  zend_call_trampoline_arginfo[0].name = ZSTR_KNOWN(ZEND_STR_ARGUMENTS);
2685
  zend_call_trampoline_arginfo[0].type = (zend_type)ZEND_TYPE_INIT_CODE(IS_MIXED, false, _ZEND_ARG_INFO_FLAGS(false, 1, 0));
2686
2
  zend_property_hook_arginfo[0].name = ZSTR_KNOWN(ZEND_STR_VALUE);
2687
2
}