Coverage Report

Created: 2025-12-14 06:06

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