Coverage Report

Created: 2026-01-18 06:48

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