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 +----------------------------------------------------------------------+
23 static inline zval
*new_zval(zend_class_entry
*ce
)
26 if (ce
->type
& ZEND_INTERNAL_CLASS
) {
27 z
= malloc(sizeof(zval
));
35 static inline zval
*tmp_zval(void)
45 #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION == 0)
46 int zend_declare_property_double(zend_class_entry
*ce
, char *name
, int name_length
, double value
, int access_type TSRMLS_DC
)
48 zval
*property
= new_zval(ce
);
49 ZVAL_DOUBLE(property
, value
);
50 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
53 void zend_update_property_double(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, double value TSRMLS_DC
)
55 zval
*tmp
= tmp_zval();
56 ZVAL_DOUBLE(tmp
, value
);
57 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
60 int zend_declare_property_bool(zend_class_entry
*ce
, char *name
, int name_length
, long value
, int access_type TSRMLS_DC
)
62 zval
*property
= new_zval(ce
);
63 ZVAL_BOOL(property
, value
);
64 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
67 void zend_update_property_bool(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, long value TSRMLS_DC
)
69 zval
*tmp
= tmp_zval();
70 ZVAL_BOOL(tmp
, value
);
71 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
76 #if (PHP_MAJOR_VERSION >= 5)
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
);
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
);
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
);
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
);
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
);
121 int zend_update_static_property(zend_class_entry
*scope
, char *name
, size_t name_len
, zval
*value TSRMLS_DC
)
124 zval
**property
= NULL
;
125 zend_class_entry
*old_scope
= EG(scope
);
128 if (!(property
= zend_std_get_static_property(scope
, name
, name_len
, 0 TSRMLS_CC
))) {
129 EG(scope
) = old_scope
;
132 EG(scope
) = old_scope
;
133 if (*property
== value
) {
137 if (scope
->type
& ZEND_INTERNAL_CLASS
) {
141 refcount
= (*property
)->refcount
;
142 is_ref
= (*property
)->is_ref
;
145 switch (Z_TYPE_PP(property
))
147 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
151 zend_list_delete(Z_LVAL_PP(property
));
154 case IS_STRING
: case IS_CONSTANT
:
155 free(Z_STRVAL_PP(property
));
159 if (Z_OBJ_HT_PP(property
)->del_ref
) {
160 Z_OBJ_HT_PP(property
)->del_ref(*property TSRMLS_CC
);
164 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
165 if (Z_ARRVAL_PP(property
) && Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
166 zend_hash_destroy(Z_ARRVAL_PP(property
));
167 free(Z_ARRVAL_PP(property
));
176 switch (Z_TYPE_PP(property
))
178 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
182 zend_list_addref(Z_LVAL_PP(property
));
185 case IS_STRING
: case IS_CONSTANT
:
186 Z_STRVAL_PP(property
) = (char *) zend_strndup(Z_STRVAL_PP(property
), Z_STRLEN_PP(property
));
190 if (Z_OBJ_HT_PP(property
)->add_ref
) {
191 Z_OBJ_HT_PP(property
)->add_ref(*property TSRMLS_CC
);
195 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
197 if (Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
199 HashTable
*old
= Z_ARRVAL_PP(property
);
201 Z_ARRVAL_PP(property
) = (HashTable
*) malloc(sizeof(HashTable
));
202 zend_hash_init(Z_ARRVAL_PP(property
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
203 zend_hash_copy(Z_ARRVAL_PP(property
), old
, (copy_ctor_func_t
) zval_add_ref
, (void *) &tmp
, sizeof(zval
*));
209 (*property
)->refcount
= refcount
;
210 (*property
)->is_ref
= is_ref
;
215 if (PZVAL_IS_REF(*property
)) {
216 zval_dtor(*property
);
217 (*property
)->type
= value
->type
;
218 (*property
)->value
= value
->value
;
220 if (value
->refcount
) {
221 zval_copy_ctor(*property
);
227 if (PZVAL_IS_REF(value
)) {
228 SEPARATE_ZVAL(&value
);
231 retval
= zend_hash_update(scope
->static_members
, name
, name_len
+1, &value
, sizeof(zval
*), NULL
);
235 if (!value
->refcount
) {
243 int zend_update_static_property_bool(zend_class_entry
*scope
, char *name
, size_t name_len
, zend_bool value TSRMLS_DC
)
245 zval
*tmp
= tmp_zval();
246 ZVAL_BOOL(tmp
, value
);
247 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
250 int zend_update_static_property_long(zend_class_entry
*scope
, char *name
, size_t name_len
, long value TSRMLS_DC
)
252 zval
*tmp
= tmp_zval();
253 ZVAL_LONG(tmp
, value
);
254 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
257 int zend_update_static_property_double(zend_class_entry
*scope
, char *name
, size_t name_len
, double value TSRMLS_DC
)
259 zval
*tmp
= tmp_zval();
260 ZVAL_DOUBLE(tmp
, value
);
261 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
264 int zend_update_static_property_string(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value TSRMLS_DC
)
266 zval
*tmp
= tmp_zval();
267 ZVAL_STRING(tmp
, value
, 1);
268 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
271 int zend_update_static_property_stringl(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value
, size_t value_len TSRMLS_DC
)
273 zval
*tmp
= tmp_zval();
274 ZVAL_STRINGL(tmp
, value
, value_len
, 1);
275 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
286 * vim600: noet sw=4 ts=4 fdm=marker
287 * vim<600: noet sw=4 ts=4