This source file includes following definitions.
- incomplete_class_message
- incomplete_class_get_property
- incomplete_class_write_property
- incomplete_class_get_property_ptr_ptr
- incomplete_class_unset_property
- incomplete_class_has_property
- incomplete_class_get_method
- php_create_incomplete_object
- php_create_incomplete_class
- php_lookup_class_name
- php_store_class_name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "php.h"
22 #include "basic_functions.h"
23 #include "php_incomplete_class.h"
24
25 #define INCOMPLETE_CLASS_MSG \
26 "The script tried to execute a method or " \
27 "access a property of an incomplete object. " \
28 "Please ensure that the class definition \"%s\" of the object " \
29 "you are trying to operate on was loaded _before_ " \
30 "unserialize() gets called or provide a __autoload() function " \
31 "to load the class definition "
32
33 static zend_object_handlers php_incomplete_object_handlers;
34
35
36
37 static void incomplete_class_message(zval *object, int error_type)
38 {
39 zend_string *class_name;
40
41 class_name = php_lookup_class_name(object);
42
43 if (class_name) {
44 php_error_docref(NULL, error_type, INCOMPLETE_CLASS_MSG, ZSTR_VAL(class_name));
45 zend_string_release(class_name);
46 } else {
47 php_error_docref(NULL, error_type, INCOMPLETE_CLASS_MSG, "unknown");
48 }
49 }
50
51
52 static zval *incomplete_class_get_property(zval *object, zval *member, int type, void **cache_slot, zval *rv)
53 {
54 incomplete_class_message(object, E_NOTICE);
55
56 if (type == BP_VAR_W || type == BP_VAR_RW) {
57 return &EG(error_zval);
58 } else {
59 return &EG(uninitialized_zval);
60 }
61 }
62
63
64 static void incomplete_class_write_property(zval *object, zval *member, zval *value, void **cache_slot)
65 {
66 incomplete_class_message(object, E_NOTICE);
67 }
68
69
70 static zval *incomplete_class_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot)
71 {
72 incomplete_class_message(object, E_NOTICE);
73 return &EG(error_zval);
74 }
75
76
77 static void incomplete_class_unset_property(zval *object, zval *member, void **cache_slot)
78 {
79 incomplete_class_message(object, E_NOTICE);
80 }
81
82
83 static int incomplete_class_has_property(zval *object, zval *member, int check_empty, void **cache_slot)
84 {
85 incomplete_class_message(object, E_NOTICE);
86 return 0;
87 }
88
89
90 static union _zend_function *incomplete_class_get_method(zend_object **object, zend_string *method, const zval *key)
91 {
92 zval zobject;
93
94 ZVAL_OBJ(&zobject, *object);
95 incomplete_class_message(&zobject, E_ERROR);
96 return NULL;
97 }
98
99
100
101
102 static zend_object *php_create_incomplete_object(zend_class_entry *class_type)
103 {
104 zend_object *object;
105
106 object = zend_objects_new( class_type);
107 object->handlers = &php_incomplete_object_handlers;
108
109 object_properties_init(object, class_type);
110
111 return object;
112 }
113
114 PHPAPI zend_class_entry *php_create_incomplete_class(void)
115 {
116 zend_class_entry incomplete_class;
117
118 INIT_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL);
119 incomplete_class.create_object = php_create_incomplete_object;
120
121 memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
122 php_incomplete_object_handlers.read_property = incomplete_class_get_property;
123 php_incomplete_object_handlers.has_property = incomplete_class_has_property;
124 php_incomplete_object_handlers.unset_property = incomplete_class_unset_property;
125 php_incomplete_object_handlers.write_property = incomplete_class_write_property;
126 php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
127 php_incomplete_object_handlers.get_method = incomplete_class_get_method;
128
129 return zend_register_internal_class(&incomplete_class);
130 }
131
132
133
134
135 PHPAPI zend_string *php_lookup_class_name(zval *object)
136 {
137 zval *val;
138 HashTable *object_properties;
139
140 object_properties = Z_OBJPROP_P(object);
141
142 if ((val = zend_hash_str_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1)) != NULL && Z_TYPE_P(val) == IS_STRING) {
143 return zend_string_copy(Z_STR_P(val));
144 }
145
146 return NULL;
147 }
148
149
150
151
152 PHPAPI void php_store_class_name(zval *object, const char *name, size_t len)
153 {
154 zval val;
155
156
157 ZVAL_STRINGL(&val, name, len);
158 zend_hash_str_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1, &val);
159 }
160
161
162
163
164
165
166
167
168
169