Coverage Report

Created: 2025-11-16 06:23

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