php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_object_handlers.h
Go to the documentation of this file.
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 +----------------------------------------------------------------------+
18*/
19
20#ifndef ZEND_OBJECT_HANDLERS_H
21#define ZEND_OBJECT_HANDLERS_H
22
23#include <stdint.h>
24
25#include "zend_hash.h"
26#include "zend_types.h"
27#include "zend_property_hooks.h"
28#include "zend_lazy_objects.h"
29
31
32#define ZEND_WRONG_PROPERTY_INFO \
33 ((struct _zend_property_info*)((intptr_t)-1))
34
35#define ZEND_DYNAMIC_PROPERTY_OFFSET ((uintptr_t)(intptr_t)(-1))
36
37/* The first 4 bits in the property offset are used within the cache slot for
38 * storing information about the property. This value may be bumped to
39 * offsetof(zend_object, properties_table) in the future. */
40#define ZEND_FIRST_PROPERTY_OFFSET (1 << 4)
41#define IS_VALID_PROPERTY_OFFSET(offset) ((intptr_t)(offset) >= ZEND_FIRST_PROPERTY_OFFSET)
42#define IS_WRONG_PROPERTY_OFFSET(offset) ((intptr_t)(offset) == 0)
43#define IS_HOOKED_PROPERTY_OFFSET(offset) \
44 ((intptr_t)(offset) > 0 && (intptr_t)(offset) < 16)
45#define IS_DYNAMIC_PROPERTY_OFFSET(offset) ((intptr_t)(offset) < 0)
46
47#define ZEND_PROPERTY_HOOK_SIMPLE_READ_BIT 2u
48#define ZEND_PROPERTY_HOOK_SIMPLE_WRITE_BIT 4u
49#define ZEND_PROPERTY_HOOK_SIMPLE_GET_BIT 8u
50#define ZEND_IS_PROPERTY_HOOK_SIMPLE_READ(offset) \
51 (((offset) & ZEND_PROPERTY_HOOK_SIMPLE_READ_BIT) != 0)
52#define ZEND_IS_PROPERTY_HOOK_SIMPLE_WRITE(offset) \
53 (((offset) & ZEND_PROPERTY_HOOK_SIMPLE_WRITE_BIT) != 0)
54#define ZEND_IS_PROPERTY_HOOK_SIMPLE_GET(offset) \
55 (((offset) & ZEND_PROPERTY_HOOK_SIMPLE_GET_BIT) != 0)
56#define ZEND_SET_PROPERTY_HOOK_SIMPLE_READ(cache_slot) \
57 do { \
58 void **__cache_slot = (cache_slot); \
59 if (__cache_slot) { \
60 CACHE_PTR_EX(__cache_slot + 1, (void*)((uintptr_t)CACHED_PTR_EX(__cache_slot + 1) | ZEND_PROPERTY_HOOK_SIMPLE_READ_BIT)); \
61 } \
62 } while (0)
63#define ZEND_SET_PROPERTY_HOOK_SIMPLE_WRITE(cache_slot) \
64 do { \
65 void **__cache_slot = (cache_slot); \
66 if (__cache_slot) { \
67 CACHE_PTR_EX(__cache_slot + 1, (void*)((uintptr_t)CACHED_PTR_EX(__cache_slot + 1) | ZEND_PROPERTY_HOOK_SIMPLE_WRITE_BIT)); \
68 } \
69 } while (0)
70#define ZEND_SET_PROPERTY_HOOK_SIMPLE_GET(cache_slot) \
71 do { \
72 void **__cache_slot = (cache_slot); \
73 if (__cache_slot) { \
74 CACHE_PTR_EX(__cache_slot + 1, (void*)((uintptr_t)CACHED_PTR_EX(__cache_slot + 1) | ZEND_PROPERTY_HOOK_SIMPLE_GET_BIT)); \
75 } \
76 } while (0)
77
78#define IS_UNKNOWN_DYNAMIC_PROPERTY_OFFSET(offset) (offset == ZEND_DYNAMIC_PROPERTY_OFFSET)
79#define ZEND_DECODE_DYN_PROP_OFFSET(offset) ((uintptr_t)(-(intptr_t)(offset) - 2))
80#define ZEND_ENCODE_DYN_PROP_OFFSET(offset) ((uintptr_t)(-((intptr_t)(offset) + 2)))
81
82
83/* Used to fetch property from the object, read-only */
84typedef zval *(*zend_object_read_property_t)(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
85
86/* Used to fetch dimension from the object, read-only */
87typedef zval *(*zend_object_read_dimension_t)(zend_object *object, zval *offset, int type, zval *rv);
88
89
90/* Used to set property of the object
91 You must return the final value of the assigned property.
92*/
93typedef zval *(*zend_object_write_property_t)(zend_object *object, zend_string *member, zval *value, void **cache_slot);
94
95/* Used to set dimension of the object */
97
98
99/* Used to create pointer to the property of the object, for future direct r/w access.
100 * May return one of:
101 * * A zval pointer, without incrementing the reference count.
102 * * &EG(error_zval), if an exception has been thrown.
103 * * NULL, if acquiring a direct pointer is not possible.
104 * In this case, the VM will fall back to using read_property and write_property.
105 */
106typedef zval *(*zend_object_get_property_ptr_ptr_t)(zend_object *object, zend_string *member, int type, void **cache_slot);
107
108/* Used to check if a property of the object exists */
109/* param has_set_exists:
110 * 0 (has) whether property exists and is not NULL
111 * 1 (set) whether property exists and is true
112 * 2 (exists) whether property exists
113 */
114typedef int (*zend_object_has_property_t)(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot);
115
116/* Used to check if a dimension of the object exists */
117typedef int (*zend_object_has_dimension_t)(zend_object *object, zval *member, int check_empty);
118
119/* Used to remove a property of the object */
120typedef void (*zend_object_unset_property_t)(zend_object *object, zend_string *member, void **cache_slot);
121
122/* Used to remove a dimension of the object */
124
125/* Used to get hash of the properties of the object, as hash of zval's */
126typedef HashTable *(*zend_object_get_properties_t)(zend_object *object);
127
128typedef HashTable *(*zend_object_get_debug_info_t)(zend_object *object, int *is_temp);
129
130typedef enum _zend_prop_purpose {
131 /* Used for debugging. Supersedes get_debug_info handler. */
133 /* Used for (array) casts. */
135 /* Used for serialization using the "O" scheme.
136 * Unserialization will use __wakeup(). */
138 /* Used for var_export().
139 * The data will be passed to __set_state() when evaluated. */
141 /* Used for json_encode(). */
143 /* Used for get_object_vars(). */
145 /* Dummy member to ensure that "default" is specified. */
148
149/* The return value must be released using zend_release_properties(). */
150typedef zend_array *(*zend_object_get_properties_for_t)(zend_object *object, zend_prop_purpose purpose);
151
152/* Used to call methods */
153/* args on stack! */
154/* Andi - EX(fbc) (function being called) needs to be initialized already in the INIT fcall opcode so that the parameters can be parsed the right way. We need to add another callback for this.
155 */
156typedef zend_function *(*zend_object_get_method_t)(zend_object **object, zend_string *method, const zval *key);
157typedef zend_function *(*zend_object_get_constructor_t)(zend_object *object);
158
159/* free_obj should release any resources the object holds, without freeing the
160 * object structure itself. The object does not need to be in a valid state after
161 * free_obj finishes running.
162 *
163 * free_obj will always be invoked, even if the object leaks or a fatal error
164 * occurs. However, during shutdown it may be called once the executor is no
165 * longer active, in which case execution of user code may be skipped.
166 */
168
169/* dtor_obj is called before free_obj. The object must remain in a valid state
170 * after dtor_obj finishes running. Unlike free_obj, it is run prior to
171 * deactivation of the executor during shutdown, which allows user code to run.
172 *
173 * This handler is not guaranteed to be called (e.g. on fatal error), and as
174 * such should not be used to release resources or deallocate memory. Furthermore,
175 * releasing resources in this handler can break detection of memory leaks, as
176 * cycles may be broken early.
177 *
178 * dtor_obj should be used *only* to call user destruction hooks, such as __destruct.
179 */
181
182typedef zend_object* (*zend_object_clone_obj_t)(zend_object *object);
183
184/* Get class name for display in var_dump and other debugging functions.
185 * Must be defined and must return a non-NULL value. */
186typedef zend_string *(*zend_object_get_class_name_t)(const zend_object *object);
187
188typedef int (*zend_object_compare_t)(zval *object1, zval *object2);
189
190/* Cast an object to some other type.
191 * readobj and retval must point to distinct zvals.
192 */
194
195/* updates *count to hold the number of elements present and returns SUCCESS.
196 * Returns FAILURE if the object does not have any sense of overloaded dimensions */
198
199typedef zend_result (*zend_object_get_closure_t)(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only);
200
201typedef HashTable *(*zend_object_get_gc_t)(zend_object *object, zval **table, int *n);
202
204
206 /* offset of real object header (usually zero) */
208 /* object handlers */
233};
234
237
238#define zend_get_std_object_handlers() \
239 (&std_object_handlers)
240
241#define zend_get_function_root_class(fbc) \
242 ((fbc)->common.prototype ? (fbc)->common.prototype->common.scope : (fbc)->common.scope)
243
244#define ZEND_PROPERTY_ISSET 0x0 /* Property exists and is not NULL */
245#define ZEND_PROPERTY_NOT_EMPTY ZEND_ISEMPTY /* Property is not empty */
246#define ZEND_PROPERTY_EXISTS 0x2 /* Property exists */
247
257ZEND_API HashTable *zend_std_get_gc(zend_object *object, zval **table, int *n);
260ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
261ZEND_API zval *zend_std_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
262ZEND_API zval *zend_std_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot);
263ZEND_API int zend_std_has_property(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot);
264ZEND_API void zend_std_unset_property(zend_object *object, zend_string *member, void **cache_slot);
267ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check_empty);
272ZEND_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);
273/* Use zend_std_get_properties_ex() */
275
276static zend_always_inline HashTable *zend_std_get_properties_ex(zend_object *object)
277{
278 if (UNEXPECTED(zend_lazy_object_must_init(object))) {
279 return zend_lazy_object_get_properties(object);
280 }
281 if (!object->properties) {
283 }
284 return object->properties;
285}
286
287/* Implements the fast path for array cast */
289
290#define ZEND_STD_BUILD_OBJECT_PROPERTIES_ARRAY_COMPATIBLE(object) ( \
291 /* We can use zend_std_build_object_properties_array() for objects \
292 * without properties ht and with standard handlers */ \
293 Z_OBJ_P(object)->properties == NULL \
294 && Z_OBJ_HT_P(object)->get_properties_for == NULL \
295 && Z_OBJ_HT_P(object)->get_properties == zend_std_get_properties \
296 /* For initialized proxies we need to forward to the real instance */ \
297 && ( \
298 !zend_object_is_lazy_proxy(Z_OBJ_P(object)) \
299 || !zend_lazy_object_initialized(Z_OBJ_P(object)) \
300 ) \
301)
302
303/* Handler for objects that cannot be meaningfully compared.
304 * Only objects with the same identity will be considered equal. */
306
308
309ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_string *prop_info_name, bool is_dynamic);
310
312
314
316
318
319/* Default behavior for get_properties_for. For use as a fallback in custom
320 * get_properties_for implementations. */
322
323/* Will call get_properties_for handler or use default behavior. For use by
324 * consumers of the get_properties_for API. */
326
328
332
335#define zend_release_properties(ht) do { \
336 if ((ht) && !(GC_FLAGS(ht) & GC_IMMUTABLE) && !GC_DELREF(ht)) { \
337 zend_array_destroy(ht); \
338 } \
339} while (0)
341#define zend_free_trampoline(func) do { \
342 if ((func) == &EG(trampoline)) { \
343 EG(trampoline).common.attributes = NULL; \
344 EG(trampoline).common.function_name = NULL; \
345 } else { \
346 efree(func); \
347 } \
348 } while (0)
349
350/* Fallback to default comparison implementation if the arguments aren't both objects
351 * and have the same compare() handler. You'll likely want to use this unless you
352 * explicitly wish to support comparisons between objects and non-objects. */
353#define ZEND_COMPARE_OBJECTS_FALLBACK(op1, op2) \
354 if (Z_TYPE_P(op1) != IS_OBJECT || \
355 Z_TYPE_P(op2) != IS_OBJECT || \
356 Z_OBJ_HT_P(op1)->compare != Z_OBJ_HT_P(op2)->compare) { \
357 return zend_std_compare_objects(op1, op2); \
358 }
359
361
362#endif
count(Countable|array $value, int $mode=COUNT_NORMAL)
zend_ffi_type * type
Definition ffi.c:3812
zend_long n
Definition ffi.c:4979
new_type kind
Definition ffi.c:4363
zend_long offset
unsigned char key[REFLECTION_KEY_LEN]
zval rv
Definition session.c:1024
zend_object_write_property_t write_property
zend_object_compare_t compare
zend_object_dtor_obj_t dtor_obj
zend_object_unset_property_t unset_property
zend_object_get_class_name_t get_class_name
zend_object_unset_dimension_t unset_dimension
zend_object_get_property_ptr_ptr_t get_property_ptr_ptr
zend_object_get_closure_t get_closure
zend_object_free_obj_t free_obj
zend_object_get_debug_info_t get_debug_info
zend_object_get_gc_t get_gc
zend_object_has_dimension_t has_dimension
zend_object_get_method_t get_method
zend_object_do_operation_t do_operation
zend_object_read_property_t read_property
zend_object_cast_t cast_object
zend_object_has_property_t has_property
zend_object_read_dimension_t read_dimension
zend_object_get_constructor_t get_constructor
zend_object_get_properties_for_t get_properties_for
zend_object_clone_obj_t clone_obj
zend_object_count_elements_t count_elements
zend_object_get_properties_t get_properties
zend_object_write_dimension_t write_dimension
zend_class_entry * ce
struct _zval_struct zval
struct _zend_property_info zend_property_info
#define ZEND_API
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
union _zend_function zend_function
ZEND_API HashTable * zend_lazy_object_get_properties(zend_object *object)
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
ZEND_API const zend_object_handlers std_object_handlers
void(* zend_object_free_obj_t)(zend_object *object)
ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_string *prop_info_name, bool is_dynamic)
ZEND_API HashTable * zend_get_properties_for(zval *obj, zend_prop_purpose purpose)
ZEND_API zend_function * zend_get_call_trampoline_func(const zend_class_entry *ce, zend_string *method_name, bool is_static)
ZEND_API HashTable * zend_std_get_debug_info(zend_object *object, int *is_temp)
ZEND_API zval * zend_std_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot)
ZEND_API HashTable * zend_get_properties_no_lazy_init(zend_object *zobj)
void(* zend_object_unset_dimension_t)(zend_object *object, zval *offset)
ZEND_API zend_string * zend_std_get_class_name(const zend_object *zobj)
zval *(* zend_object_get_property_ptr_ptr_t)(zend_object *object, zend_string *member, int type, void **cache_slot)
enum _zend_prop_purpose zend_prop_purpose
ZEND_API zval * zend_std_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
ZEND_API int zend_std_has_property(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot)
ZEND_API struct _zend_property_info * zend_get_property_info(const zend_class_entry *ce, zend_string *member, int silent)
ZEND_API HashTable * zend_std_get_gc(zend_object *object, zval **table, int *n)
void(* zend_object_unset_property_t)(zend_object *object, zend_string *member, void **cache_slot)
HashTable *(* zend_object_get_debug_info_t)(zend_object *object, int *is_temp)
ZEND_API zval * zend_std_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot)
zend_result(* zend_object_do_operation_t)(uint8_t opcode, zval *result, zval *op1, zval *op2)
HashTable *(* zend_object_get_properties_t)(zend_object *object)
ZEND_API zend_function * zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key)
ZEND_API uint32_t * zend_get_recursion_guard(zend_object *zobj)
ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check_empty)
ZEND_API bool zend_check_protected(const zend_class_entry *ce, const zend_class_entry *scope)
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
ZEND_API HashTable * zend_std_get_properties_for(zend_object *obj, zend_prop_purpose purpose)
zend_result(* zend_object_get_closure_t)(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only)
ZEND_API ZEND_COLD bool zend_std_unset_static_property(zend_class_entry *ce, zend_string *property_name)
ZEND_API zend_function * zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name_strval, const zval *key)
zval *(* zend_object_read_dimension_t)(zend_object *object, zval *offset, int type, zval *rv)
ZEND_API HashTable * zend_std_build_object_properties_array(zend_object *zobj)
int(* zend_object_has_property_t)(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot)
zval *(* zend_object_read_property_t)(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
zend_object *(* zend_object_clone_obj_t)(zend_object *object)
zend_array *(* zend_object_get_properties_for_t)(zend_object *object, zend_prop_purpose purpose)
ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset)
int(* zend_object_compare_t)(zval *object1, zval *object2)
ZEND_API uint32_t * zend_get_property_guard(zend_object *zobj, zend_string *member)
ZEND_API HashTable * zend_std_get_properties(zend_object *object)
zend_function *(* zend_object_get_constructor_t)(zend_object *object)
int(* zend_object_has_dimension_t)(zend_object *object, zval *member, int check_empty)
void(* zend_object_write_dimension_t)(zend_object *object, zval *offset, zval *value)
zend_result(* zend_object_count_elements_t)(zend_object *object, zend_long *count)
@ ZEND_PROP_PURPOSE_DEBUG
@ ZEND_PROP_PURPOSE_SERIALIZE
@ ZEND_PROP_PURPOSE_ARRAY_CAST
@ ZEND_PROP_PURPOSE_GET_OBJECT_VARS
@ ZEND_PROP_PURPOSE_VAR_EXPORT
@ ZEND_PROP_PURPOSE_JSON
@ _ZEND_PROP_PURPOSE_NON_EXHAUSTIVE_ENUM
ZEND_API zval * zend_std_read_dimension(zend_object *object, zval *offset, int type, zval *rv)
zend_string *(* zend_object_get_class_name_t)(const zend_object *object)
ZEND_API zend_function * zend_std_get_constructor(zend_object *object)
ZEND_API int zend_std_compare_objects(zval *o1, zval *o2)
ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval *value)
ZEND_API zval * zend_std_get_static_property_with_info(zend_class_entry *ce, zend_string *property_name, int type, struct _zend_property_info **prop_info)
ZEND_API zend_function * zend_get_property_hook_trampoline(const zend_property_info *prop_info, zend_property_hook_kind kind, zend_string *prop_name)
ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_property_info *prop_info)
zend_result(* zend_object_cast_t)(zend_object *readobj, zval *retval, int type)
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *object, zval *writeobj, int type)
ZEND_API void zend_std_unset_property(zend_object *object, zend_string *member, void **cache_slot)
ZEND_API HashTable * rebuild_object_properties_internal(zend_object *zobj)
HashTable *(* zend_object_get_gc_t)(zend_object *object, zval **table, int *n)
zval *(* zend_object_write_property_t)(zend_object *object, zend_string *member, zval *value, void **cache_slot)
void(* zend_object_dtor_obj_t)(zend_object *object)
zend_function *(* zend_object_get_method_t)(zend_object **object, zend_string *method, const zval *key)
ZEND_API void zend_class_init_statics(zend_class_entry *ce)
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)
ZEND_API zval * zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, int type)
#define END_EXTERN_C()
#define zend_always_inline
#define ZEND_FASTCALL
#define ZEND_COLD
#define UNEXPECTED(condition)
#define BEGIN_EXTERN_C()
struct _zend_array zend_array
zend_property_hook_kind
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_array HashTable
Definition zend_types.h:386
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
zval retval
zend_property_info * prop_info
bool result
op2
op1
object
value
new_op_array scope
zend_object * zobj