Coverage Report

Created: 2025-07-23 06:33

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