Coverage Report

Created: 2026-04-01 06:49

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