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