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)
47 int zend_declare_property_double(zend_class_entry
*ce
, char *name
, int name_length
, double value
, int access_type TSRMLS_DC
)
49 zval
*property
= new_zval(ce
);
50 ZVAL_DOUBLE(property
, value
);
51 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
54 void zend_update_property_double(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, double value TSRMLS_DC
)
56 zval
*tmp
= tmp_zval();
57 ZVAL_DOUBLE(tmp
, value
);
58 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
61 int zend_declare_property_bool(zend_class_entry
*ce
, char *name
, int name_length
, long value
, int access_type TSRMLS_DC
)
63 zval
*property
= new_zval(ce
);
64 ZVAL_BOOL(property
, value
);
65 return zend_declare_property(ce
, name
, name_length
, property
, access_type TSRMLS_CC
);
68 void zend_update_property_bool(zend_class_entry
*scope
, zval
*object
, char *name
, int name_length
, long value TSRMLS_DC
)
70 zval
*tmp
= tmp_zval();
71 ZVAL_BOOL(tmp
, value
);
72 zend_update_property(scope
, object
, name
, name_length
, tmp TSRMLS_CC
);
75 #endif /* PHP_VERSION == 5.0 */
77 #if (PHP_MAJOR_VERSION >= 5)
79 int zend_declare_class_constant(zend_class_entry
*ce
, char *name
, size_t name_length
, zval
*value TSRMLS_DC
)
81 return zend_hash_add(&ce
->constants_table
, name
, name_length
, &value
, sizeof(zval
*), NULL
);
84 int zend_declare_class_constant_long(zend_class_entry
*ce
, char *name
, size_t name_length
, long value TSRMLS_DC
)
86 zval
*constant
= new_zval(ce
);
87 ZVAL_LONG(constant
, value
);
88 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
91 int zend_declare_class_constant_bool(zend_class_entry
*ce
, char *name
, size_t name_length
, zend_bool value TSRMLS_DC
)
93 zval
*constant
= new_zval(ce
);
94 ZVAL_BOOL(constant
, value
);
95 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
98 int zend_declare_class_constant_double(zend_class_entry
*ce
, char *name
, size_t name_length
, double value TSRMLS_DC
)
100 zval
*constant
= new_zval(ce
);
101 ZVAL_DOUBLE(constant
, value
);
102 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
105 int zend_declare_class_constant_string(zend_class_entry
*ce
, char *name
, size_t name_length
, char *value TSRMLS_DC
)
107 return zend_declare_class_constant_stringl(ce
, name
, name_length
, value
, strlen(value
) TSRMLS_CC
);
110 int zend_declare_class_constant_stringl(zend_class_entry
*ce
, char *name
, size_t name_length
, char *value
, size_t value_length TSRMLS_DC
)
112 zval
*constant
= new_zval(ce
);
113 if (ce
->type
& ZEND_INTERNAL_CLASS
) {
114 ZVAL_STRINGL(constant
, zend_strndup(value
, value_length
), value_length
, 0);
116 ZVAL_STRINGL(constant
, value
, value_length
, 1);
118 return zend_declare_class_constant(ce
, name
, name_length
, constant TSRMLS_CC
);
122 int zend_update_static_property(zend_class_entry
*scope
, char *name
, size_t name_len
, zval
*value TSRMLS_DC
)
125 zval
**property
= NULL
;
126 zend_class_entry
*old_scope
= EG(scope
);
130 if (!(property
= zend_std_get_static_property(scope
, name
, name_len
, 0 TSRMLS_CC
))) {
132 } else if (*property
== value
) {
134 } else if (scope
->type
& ZEND_INTERNAL_CLASS
) {
138 refcount
= (*property
)->refcount
;
139 is_ref
= (*property
)->is_ref
;
142 switch (Z_TYPE_PP(property
))
144 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
148 zend_list_delete(Z_LVAL_PP(property
));
151 case IS_STRING
: case IS_CONSTANT
:
152 free(Z_STRVAL_PP(property
));
156 if (Z_OBJ_HT_PP(property
)->del_ref
) {
157 Z_OBJ_HT_PP(property
)->del_ref(*property TSRMLS_CC
);
161 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
162 if (Z_ARRVAL_PP(property
) && Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
163 zend_hash_destroy(Z_ARRVAL_PP(property
));
164 free(Z_ARRVAL_PP(property
));
173 switch (Z_TYPE_PP(property
))
175 case IS_BOOL
: case IS_LONG
: case IS_NULL
:
179 zend_list_addref(Z_LVAL_PP(property
));
182 case IS_STRING
: case IS_CONSTANT
:
183 Z_STRVAL_PP(property
) = (char *) zend_strndup(Z_STRVAL_PP(property
), Z_STRLEN_PP(property
));
187 if (Z_OBJ_HT_PP(property
)->add_ref
) {
188 Z_OBJ_HT_PP(property
)->add_ref(*property TSRMLS_CC
);
192 case IS_ARRAY
: case IS_CONSTANT_ARRAY
:
194 if (Z_ARRVAL_PP(property
) != &EG(symbol_table
)) {
196 HashTable
*old
= Z_ARRVAL_PP(property
);
198 Z_ARRVAL_PP(property
) = (HashTable
*) malloc(sizeof(HashTable
));
199 zend_hash_init(Z_ARRVAL_PP(property
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
200 zend_hash_copy(Z_ARRVAL_PP(property
), old
, (copy_ctor_func_t
) zval_add_ref
, (void *) &tmp
, sizeof(zval
*));
206 (*property
)->refcount
= refcount
;
207 (*property
)->is_ref
= is_ref
;
212 if (PZVAL_IS_REF(*property
)) {
213 zval_dtor(*property
);
214 (*property
)->type
= value
->type
;
215 (*property
)->value
= value
->value
;
217 if (value
->refcount
) {
218 zval_copy_ctor(*property
);
224 if (PZVAL_IS_REF(value
)) {
225 SEPARATE_ZVAL(&value
);
228 retval
= zend_hash_update(scope
->static_members
, name
, name_len
, &value
, sizeof(zval
*), NULL
);
232 if (!value
->refcount
) {
237 EG(scope
) = old_scope
;
242 int zend_update_static_property_bool(zend_class_entry
*scope
, char *name
, size_t name_len
, zend_bool value TSRMLS_DC
)
244 zval
*tmp
= tmp_zval();
245 ZVAL_BOOL(tmp
, value
);
246 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
249 int zend_update_static_property_long(zend_class_entry
*scope
, char *name
, size_t name_len
, long value TSRMLS_DC
)
251 zval
*tmp
= tmp_zval();
252 ZVAL_LONG(tmp
, value
);
253 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
256 int zend_update_static_property_double(zend_class_entry
*scope
, char *name
, size_t name_len
, double value TSRMLS_DC
)
258 zval
*tmp
= tmp_zval();
259 ZVAL_DOUBLE(tmp
, value
);
260 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
263 int zend_update_static_property_string(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value TSRMLS_DC
)
265 zval
*tmp
= tmp_zval();
266 ZVAL_STRING(tmp
, value
, 1);
267 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
270 int zend_update_static_property_stringl(zend_class_entry
*scope
, char *name
, size_t name_len
, char *value
, size_t value_len TSRMLS_DC
)
272 zval
*tmp
= tmp_zval();
273 ZVAL_STRINGL(tmp
, value
, value_len
, 1);
274 return zend_update_static_property(scope
, name
, name_len
, tmp TSRMLS_CC
);
277 #endif /* PHP_MAJOR_VERSION >= 5 */
278 #endif /* ZEND_ENGINE_2 */
285 * vim600: noet sw=4 ts=4 fdm=marker
286 * vim<600: noet sw=4 ts=4