2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
21 #if PHP_MAJOR_VERSION == 5
23 static inline zval
*new_zval(int persistent
)
25 zval
*z
= pemalloc(sizeof(zval
), persistent
);
30 static inline zval
*tmp_zval(void)
39 static void dup_zval(zval
**z
)
46 # if PHP_MINOR_VERSION == 0
48 int zend_declare_property_double(zend_class_entry
*ce
, char *name
, int name_length
, double value
, int access_type TSRMLS_DC
)
50 zval
*property
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
51 ZVAL_DOUBLE(property
, value
);
52 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
55 void zend_update_property_double(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, double value TSRMLS_DC
)
57 zval
*tmp
= tmp_zval();
58 ZVAL_DOUBLE(tmp
, value
);
59 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
62 int zend_declare_property_bool(zend_class_entry
*ce
, char *name
, int name_length
, long value
, int access_type TSRMLS_DC
)
64 zval
*property
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
65 ZVAL_BOOL(property
, value
);
66 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
69 void zend_update_property_bool(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, long value TSRMLS_DC
)
71 zval
*tmp
= tmp_zval();
72 ZVAL_BOOL(tmp
, value
);
73 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
76 # endif /* PHP_MINOR_VERSION == 0 */
78 int zend_declare_class_constant(zend_class_entry
*ce
, char *name
, size_t name_length
, zval
*value TSRMLS_DC
)
80 return zend_hash_add(&ce
->constants_table
, name
, name_length
, &value
, sizeof(zval
*), NULL
);
83 int zend_declare_class_constant_long(zend_class_entry
*ce
, char *name
, size_t name_length
, long value TSRMLS_DC
)
85 zval
*constant
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
86 ZVAL_LONG(constant
, value
);
87 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
90 int zend_declare_class_constant_bool(zend_class_entry
*ce
, char *name
, size_t name_length
, zend_bool value TSRMLS_DC
)
92 zval
*constant
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
93 ZVAL_BOOL(constant
, value
);
94 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
97 int zend_declare_class_constant_double(zend_class_entry
*ce
, char *name
, size_t name_length
, double value TSRMLS_DC
)
99 zval
*constant
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
100 ZVAL_DOUBLE(constant
, value
);
101 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
104 int zend_declare_class_constant_string(zend_class_entry
*ce
, char *name
, size_t name_length
, char *value TSRMLS_DC
)
106 return zend_declare_class_constant_stringl(ce
, name
, name_length
, value
, strlen(value
) TSRMLS_CC
);
109 int zend_declare_class_constant_stringl(zend_class_entry
*ce
, char *name
, size_t name_length
, char *value
, size_t value_length TSRMLS_DC
)
111 zval
*constant
= new_zval(ce
->type
& ZEND_INTERNAL_CLASS
);
112 if (ce
->type
& ZEND_INTERNAL_CLASS
) {
113 ZVAL_STRINGL(constant
, zend_strndup(value
, value_length
), value_length
, 0);
115 ZVAL_STRINGL(constant
, value
, value_length
, 1);
117 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
120 int zend_update_static_property(zend_class_entry
*scope
, char *name
, size_t name_len
, zval
*value TSRMLS_DC
)
123 zval
**property
= NULL
;
124 zend_class_entry
*old_scope
= EG(scope
);
128 if (!(property
= zend_std_get_static_property(scope
, name
, name_len
, 0 TSRMLS_CC
))) {
130 } else if (*property
== value
) {
133 if (PZVAL_IS_REF(*property
)) {
134 zval_dtor(*property
);
135 (*property
)->type
= value
->type
;
136 (*property
)->value
= value
->value
;
138 if (value
->refcount
) {
139 zval_copy_ctor(*property
);
143 zval_copy_ctor(*property
);
148 if (!value
->refcount
) {
153 EG(scope
) = old_scope
;
158 int trash(zend_class_entry
*scope
, char *name
, size_t name_len
, zval
*value TSRMLS_DC
)
161 zval
**property
= NULL
;
162 zend_class_entry
*old_scope
= EG(scope
);
166 if (!(property
= zend_std_get_static_property(scope
, name
, name_len
, 0 TSRMLS_CC
))) {
168 } else if (*property
== value
) {
170 } else if (scope
->type
& ZEND_INTERNAL_CLASS
) {
174 refcount
= (*property
)->refcount
;
175 is_ref
= (*property
)->is_ref
;
178 switch (Z_TYPE_PP(property
))
180 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
184 zend_list_delete(Z_LVAL_PP(property
));
187 case IS_STRING
: case IS_CONSTANT
:
188 free(Z_STRVAL_PP(property
));
192 if (Z_OBJ_HT_PP(property
)->del_ref
) {
193 Z_OBJ_HT_PP(property
)->del_ref(*property TSRMLS_CC
);
197 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
198 if (Z_ARRVAL_PP(property
) && Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
199 zend_hash_destroy(Z_ARRVAL_PP(property
));
200 free(Z_ARRVAL_PP(property
));
209 switch (Z_TYPE_PP(property
))
211 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
215 zend_list_addref(Z_LVAL_PP(property
));
218 case IS_STRING
: case IS_CONSTANT
:
219 Z_STRVAL_PP(property
) = (char *) zend_strndup(Z_STRVAL_PP(property
), Z_STRLEN_PP(property
));
223 if (Z_OBJ_HT_PP(property
)->add_ref
) {
224 Z_OBJ_HT_PP(property
)->add_ref(*property TSRMLS_CC
);
228 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
230 if (Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
232 HashTable
*old
= Z_ARRVAL_PP(property
);
234 Z_ARRVAL_PP(property
) = (HashTable
*) malloc(sizeof(HashTable
));
235 zend_hash_init(Z_ARRVAL_PP(property
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
236 zend_hash_copy(Z_ARRVAL_PP(property
), old
, (copy_ctor_func_t
) zval_add_ref
, (void *) &tmp
, sizeof(zval
*));
242 (*property
)->refcount
= refcount
;
243 (*property
)->is_ref
= is_ref
;
248 if (PZVAL_IS_REF(*property
)) {
249 zval_dtor(*property
);
250 (*property
)->type
= value
->type
;
251 (*property
)->value
= value
->value
;
253 if (value
->refcount
) {
254 zval_copy_ctor(*property
);
260 if (PZVAL_IS_REF(value
)) {
261 SEPARATE_ZVAL(&value
);
264 retval
= zend_hash_update(scope
->static_members
, name
, name_len
, &value
, sizeof(zval
*), NULL
);
268 if (!value
->refcount
) {
273 EG(scope
) = old_scope
;
278 int zend_update_static_property_bool(zend_class_entry
*scope
, char *name
, size_t name_len
, zend_bool value TSRMLS_DC
)
280 zval
*tmp
= tmp_zval();
281 ZVAL_BOOL(tmp
, value
);
282 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
285 int zend_update_static_property_long(zend_class_entry
*scope
, char *name
, size_t name_len
, long value TSRMLS_DC
)
287 zval
*tmp
= tmp_zval();
288 ZVAL_LONG(tmp
, value
);
289 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
292 int zend_update_static_property_double(zend_class_entry
*scope
, char *name
, size_t name_len
, double value TSRMLS_DC
)
294 zval
*tmp
= tmp_zval();
295 ZVAL_DOUBLE(tmp
, value
);
296 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
299 int zend_update_static_property_string(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value TSRMLS_DC
)
301 zval
*tmp
= tmp_zval();
302 ZVAL_STRING(tmp
, value
, 1);
303 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
306 int zend_update_static_property_stringl(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value
, size_t value_len TSRMLS_DC
)
308 zval
*tmp
= tmp_zval();
309 ZVAL_STRINGL(tmp
, value
, value_len
, 1);
310 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
313 void zend_fix_static_properties(zend_class_entry
*ce
, HashTable
*static_members TSRMLS_DC
)
315 zend_hash_copy(static_members
, ce
->static_members
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
316 zend_hash_destroy(ce
->static_members
);
317 zend_hash_init_ex(ce
->static_members
, 0, NULL
, ZVAL_PTR_DTOR
, 1, 0);
320 void zend_init_static_properties(zend_class_entry
*ce
, HashTable
*static_members TSRMLS_DC
)
322 zend_hash_copy(ce
->static_members
, static_members
, (copy_ctor_func_t
) dup_zval
, NULL
, sizeof(zval
*));
325 void zend_clean_static_properties(zend_class_entry
*ce TSRMLS_DC
)
327 zend_hash_clean(ce
->static_members
);
330 #endif /* PHP_MAJOR_VERSION == 5 */
337 * vim600: noet sw=4 ts=4 fdm=marker
338 * vim<600: noet sw=4 ts=4