From: Antony Dovgal Date: Tue, 29 Jul 2008 08:47:21 +0000 (+0000) Subject: add zend_u_read_property() and zend_u_update_property() X-Git-Tag: BEFORE_HEAD_NS_CHANGE~982 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=182de3e9079e0b061a984271bffef75816d2a110;p=php add zend_u_read_property() and zend_u_update_property() --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index d606e6d6a8..1e66251788 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3836,6 +3836,34 @@ ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char * } /* }}} */ +ZEND_API void zend_u_update_property(zend_class_entry *scope, zval *object, zend_uchar type, zstr name, int name_length, zval *value TSRMLS_DC) /* {{{ */ +{ + zval *property; + zend_class_entry *old_scope = EG(scope); + + EG(scope) = scope; + + if (!Z_OBJ_HT_P(object)->write_property) { + zstr class_name; + zend_uint class_name_len; + + zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); + + zend_error(E_CORE_ERROR, "Property %v of class %v cannot be updated", name.v, class_name.v); + } + MAKE_STD_ZVAL(property); + if (type == IS_UNICODE) { + ZVAL_UNICODEL(property, name.u, name_length, 1); + } else { + ZVAL_ASCII_STRINGL(property, name.s, name_length, 1); + } + Z_OBJ_HT_P(object)->write_property(object, property, value TSRMLS_CC); + zval_ptr_dtor(&property); + + EG(scope) = old_scope; +} +/* }}} */ + ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC) /* {{{ */ { zval *tmp; @@ -4184,6 +4212,35 @@ ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, char *n } /* }}} */ +ZEND_API zval *zend_u_read_property(zend_class_entry *scope, zval *object, zend_uchar type, zstr name, int name_length, zend_bool silent TSRMLS_DC) /* {{{ */ +{ + zval *property, *value; + zend_class_entry *old_scope = EG(scope); + + EG(scope) = scope; + + if (!Z_OBJ_HT_P(object)->read_property) { + zstr class_name; + zend_uint class_name_len; + + zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); + zend_error(E_CORE_ERROR, "Property %v of class %v cannot be read", name.v, class_name.v); + } + + MAKE_STD_ZVAL(property); + if (type == IS_UNICODE) { + ZVAL_UNICODEL(property, name.u, name_length, 1); + } else { + ZVAL_ASCII_STRINGL(property, name.s, name_length, 1); + } + value = Z_OBJ_HT_P(object)->read_property(object, property, silent?BP_VAR_IS:BP_VAR_R TSRMLS_CC); + zval_ptr_dtor(&property); + + EG(scope) = old_scope; + return value; +} +/* }}} */ + ZEND_API zval *zend_read_static_property(zend_class_entry *scope, char *name, int name_length, zend_bool silent TSRMLS_DC) /* {{{ */ { zval **property; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index df6b1198b7..34b1c2c692 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -311,6 +311,7 @@ ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, char *name ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC); ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC); +ZEND_API void zend_u_update_property(zend_class_entry *scope, zval *object, zend_uchar type, zstr name, int name_length, zval *value TSRMLS_DC); ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); @@ -354,6 +355,7 @@ ZEND_API int zend_update_static_property_unicode(zend_class_entry *scope, char * ZEND_API int zend_update_static_property_unicodel(zend_class_entry *scope, char *name, int name_length, UChar *value, int value_length TSRMLS_DC); ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, char *name, int name_length, zend_bool silent TSRMLS_DC); +ZEND_API zval *zend_u_read_property(zend_class_entry *scope, zval *object, zend_uchar type, zstr name, int name_length, zend_bool silent TSRMLS_DC); ZEND_API zval *zend_read_static_property(zend_class_entry *scope, char *name, int name_length, zend_bool silent TSRMLS_DC);