Coverage Report

Created: 2025-12-14 06:09

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