Coverage Report

Created: 2025-12-14 06:09

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