1 /* 2 +----------------------------------------------------------------------+ 3 | Zend Engine | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1998-2017 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@zend.com> | 16 | Zeev Suraski <zeev@zend.com> | 17 +----------------------------------------------------------------------+ 18 */ 19 20 /* $Id$ */ 21 22 #ifndef ZEND_OBJECT_HANDLERS_H 23 #define ZEND_OBJECT_HANDLERS_H 24 25 struct _zend_property_info; 26 27 #define ZEND_WRONG_PROPERTY_INFO \ 28 ((struct _zend_property_info*)((zend_intptr_t)-1)) 29 30 #define ZEND_DYNAMIC_PROPERTY_OFFSET (-1) 31 #define ZEND_WRONG_PROPERTY_OFFSET (-2) 32 33 /* The following rule applies to read_property() and read_dimension() implementations: 34 If you return a zval which is not otherwise referenced by the extension or the engine's 35 symbol table, its reference count should be 0. 36 */ 37 /* Used to fetch property from the object, read-only */ 38 typedef zval *(*zend_object_read_property_t)(zval *object, zval *member, int type, void **cache_slot, zval *rv); 39 40 /* Used to fetch dimension from the object, read-only */ 41 typedef zval *(*zend_object_read_dimension_t)(zval *object, zval *offset, int type, zval *rv); 42 43 44 /* The following rule applies to write_property() and write_dimension() implementations: 45 If you receive a value zval in write_property/write_dimension, you may only modify it if 46 its reference count is 1. Otherwise, you must create a copy of that zval before making 47 any changes. You should NOT modify the reference count of the value passed to you. 48 */ 49 /* Used to set property of the object */ 50 typedef void (*zend_object_write_property_t)(zval *object, zval *member, zval *value, void **cache_slot); 51 52 /* Used to set dimension of the object */ 53 typedef void (*zend_object_write_dimension_t)(zval *object, zval *offset, zval *value); 54 55 56 /* Used to create pointer to the property of the object, for future direct r/w access */ 57 typedef zval *(*zend_object_get_property_ptr_ptr_t)(zval *object, zval *member, int type, void **cache_slot); 58 59 /* Used to set object value. Can be used to override assignments and scalar 60 write ops (like ++, +=) on the object */ 61 typedef void (*zend_object_set_t)(zval *object, zval *value); 62 63 /* Used to get object value. Can be used when converting object value to 64 * one of the basic types and when using scalar ops (like ++, +=) on the object 65 */ 66 typedef zval* (*zend_object_get_t)(zval *object, zval *rv); 67 68 /* Used to check if a property of the object exists */ 69 /* param has_set_exists: 70 * 0 (has) whether property exists and is not NULL 71 * 1 (set) whether property exists and is true 72 * 2 (exists) whether property exists 73 */ 74 typedef int (*zend_object_has_property_t)(zval *object, zval *member, int has_set_exists, void **cache_slot); 75 76 /* Used to check if a dimension of the object exists */ 77 typedef int (*zend_object_has_dimension_t)(zval *object, zval *member, int check_empty); 78 79 /* Used to remove a property of the object */ 80 typedef void (*zend_object_unset_property_t)(zval *object, zval *member, void **cache_slot); 81 82 /* Used to remove a dimension of the object */ 83 typedef void (*zend_object_unset_dimension_t)(zval *object, zval *offset); 84 85 /* Used to get hash of the properties of the object, as hash of zval's */ 86 typedef HashTable *(*zend_object_get_properties_t)(zval *object); 87 88 typedef HashTable *(*zend_object_get_debug_info_t)(zval *object, int *is_temp); 89 90 /* Used to call methods */ 91 /* args on stack! */ 92 /* 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. 93 */ 94 typedef int (*zend_object_call_method_t)(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS); 95 typedef union _zend_function *(*zend_object_get_method_t)(zend_object **object, zend_string *method, const zval *key); 96 typedef union _zend_function *(*zend_object_get_constructor_t)(zend_object *object); 97 98 /* Object maintenance/destruction */ 99 typedef void (*zend_object_dtor_obj_t)(zend_object *object); 100 typedef void (*zend_object_free_obj_t)(zend_object *object); 101 typedef zend_object* (*zend_object_clone_obj_t)(zval *object); 102 103 /* Get class name for display in var_dump and other debugging functions. 104 * Must be defined and must return a non-NULL value. */ 105 typedef zend_string *(*zend_object_get_class_name_t)(const zend_object *object); 106 107 typedef int (*zend_object_compare_t)(zval *object1, zval *object2); 108 typedef int (*zend_object_compare_zvals_t)(zval *resul, zval *op1, zval *op2); 109 110 /* Cast an object to some other type 111 */ 112 typedef int (*zend_object_cast_t)(zval *readobj, zval *retval, int type); 113 114 /* updates *count to hold the number of elements present and returns SUCCESS. 115 * Returns FAILURE if the object does not have any sense of overloaded dimensions */ 116 typedef int (*zend_object_count_elements_t)(zval *object, zend_long *count); 117 118 typedef int (*zend_object_get_closure_t)(zval *obj, zend_class_entry **ce_ptr, union _zend_function **fptr_ptr, zend_object **obj_ptr); 119 120 typedef HashTable *(*zend_object_get_gc_t)(zval *object, zval **table, int *n); 121 122 typedef int (*zend_object_do_operation_t)(zend_uchar opcode, zval *result, zval *op1, zval *op2); 123 124 struct _zend_object_handlers { 125 /* offset of real object header (usually zero) */ 126 int offset; 127 /* general object functions */ 128 zend_object_free_obj_t free_obj; 129 zend_object_dtor_obj_t dtor_obj; 130 zend_object_clone_obj_t clone_obj; 131 /* individual object functions */ 132 zend_object_read_property_t read_property; 133 zend_object_write_property_t write_property; 134 zend_object_read_dimension_t read_dimension; 135 zend_object_write_dimension_t write_dimension; 136 zend_object_get_property_ptr_ptr_t get_property_ptr_ptr; 137 zend_object_get_t get; 138 zend_object_set_t set; 139 zend_object_has_property_t has_property; 140 zend_object_unset_property_t unset_property; 141 zend_object_has_dimension_t has_dimension; 142 zend_object_unset_dimension_t unset_dimension; 143 zend_object_get_properties_t get_properties; 144 zend_object_get_method_t get_method; 145 zend_object_call_method_t call_method; 146 zend_object_get_constructor_t get_constructor; 147 zend_object_get_class_name_t get_class_name; 148 zend_object_compare_t compare_objects; 149 zend_object_cast_t cast_object; 150 zend_object_count_elements_t count_elements; 151 zend_object_get_debug_info_t get_debug_info; 152 zend_object_get_closure_t get_closure; 153 zend_object_get_gc_t get_gc; 154 zend_object_do_operation_t do_operation; 155 zend_object_compare_zvals_t compare; 156 }; 157 158 BEGIN_EXTERN_C() 159 extern ZEND_API zend_object_handlers std_object_handlers; 160 161 #define zend_get_function_root_class(fbc) \ 162 ((fbc)->common.prototype ? (fbc)->common.prototype->common.scope : (fbc)->common.scope) 163 164 ZEND_API union _zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name_strval, const zval *key); 165 ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, zend_bool silent); 166 ZEND_API ZEND_COLD zend_bool zend_std_unset_static_property(zend_class_entry *ce, zend_string *property_name); 167 ZEND_API union _zend_function *zend_std_get_constructor(zend_object *object); 168 ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce, zend_string *member, int silent); 169 ZEND_API HashTable *zend_std_get_properties(zval *object); 170 ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp); 171 ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type); 172 ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, void **cache_slot); 173 ZEND_API void rebuild_object_properties(zend_object *zobj); 174 175 ZEND_API int zend_check_private(union _zend_function *fbc, zend_class_entry *ce, zend_string *function_name); 176 177 ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope); 178 179 ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_info_name); 180 181 ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend_string *method_name, int is_static); 182 183 #define zend_free_trampoline(func) do { \ 184 if ((func) == &EG(trampoline)) { \ 185 EG(trampoline).common.function_name = NULL; \ 186 } else { \ 187 efree(func); \ 188 } \ 189 } while (0) 190 191 END_EXTERN_C() 192 193 #endif 194 195 /* 196 * Local variables: 197 * tab-width: 4 198 * c-basic-offset: 4 199 * indent-tabs-mode: t 200 * End: 201 */ 202