Coverage Report

Created: 2026-06-02 06:40

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