Coverage Report

Created: 2026-06-02 06:37

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