]> granicus.if.org Git - php/commitdiff
add zend_u_read_property() and zend_u_update_property()
authorAntony Dovgal <tony2001@php.net>
Tue, 29 Jul 2008 08:47:21 +0000 (08:47 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 29 Jul 2008 08:47:21 +0000 (08:47 +0000)
Zend/zend_API.c
Zend/zend_API.h

index d606e6d6a82d04da3d32fea48c9ee917155df2dc..1e66251788b0448404cf2e86421122e229655105 100644 (file)
@@ -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;
index df6b1198b721d94b4c61c38940eed6e992061d89..34b1c2c692a1b947266973515cc2123ae6532a80 100644 (file)
@@ -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);