Coverage Report

Created: 2025-12-14 06:10

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