From: Marcus Boerger Date: Sun, 24 Aug 2003 00:36:53 +0000 (+0000) Subject: Add property read code and use that in default exception class X-Git-Tag: RELEASE_0_7~497 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38805f28098dcf7f27588c605eaba214ab044031;p=php Add property read code and use that in default exception class --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index e25a111677..50a2ad1de9 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1738,6 +1738,23 @@ ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); } +ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, char *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) { + zend_error(E_CORE_ERROR, "Property %s of class %s cannot be read", Z_OBJCE_P(object)->name, name); + } + ZVAL_STRINGL(&property, name, name_length, 0); + value = Z_OBJ_HT_P(object)->read_property(object, &property, silent TSRMLS_CC); + + EG(scope) = old_scope; + return value; +} + /* * Local variables: * tab-width: 4 diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 7e4ef3ad5b..02e0714311 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -172,6 +172,8 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, c ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, char *name, int name_length, char *value 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 zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC); #define getThis() (this_ptr) diff --git a/Zend/zend_default_classes.c b/Zend/zend_default_classes.c index 14fce64b38..f91507fea8 100644 --- a/Zend/zend_default_classes.c +++ b/Zend/zend_default_classes.c @@ -72,13 +72,11 @@ ZEND_FUNCTION(exception) static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) { - zval **value; + zval *value; - if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) { - RETURN_FALSE; - } + value = zend_read_property(Z_OBJCE_P(object), object, name, name_len, 0 TSRMLS_CC); - *return_value = **value; + *return_value = *value; zval_copy_ctor(return_value); } @@ -86,28 +84,28 @@ ZEND_FUNCTION(getfile) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "file", sizeof("file"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "file", sizeof("file")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getline) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "line", sizeof("line"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "line", sizeof("line")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getmessage) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "message", sizeof("message"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "message", sizeof("message")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getcode) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "code", sizeof("code"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "code", sizeof("code")-1, return_value TSRMLS_CC); } static zend_function_entry default_exception_functions[] = { diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 14fce64b38..f91507fea8 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -72,13 +72,11 @@ ZEND_FUNCTION(exception) static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) { - zval **value; + zval *value; - if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) { - RETURN_FALSE; - } + value = zend_read_property(Z_OBJCE_P(object), object, name, name_len, 0 TSRMLS_CC); - *return_value = **value; + *return_value = *value; zval_copy_ctor(return_value); } @@ -86,28 +84,28 @@ ZEND_FUNCTION(getfile) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "file", sizeof("file"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "file", sizeof("file")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getline) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "line", sizeof("line"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "line", sizeof("line")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getmessage) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "message", sizeof("message"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "message", sizeof("message")-1, return_value TSRMLS_CC); } ZEND_FUNCTION(getcode) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "code", sizeof("code"), return_value TSRMLS_CC); + _default_exception_get_entry(getThis(), "code", sizeof("code")-1, return_value TSRMLS_CC); } static zend_function_entry default_exception_functions[] = {