diff options
author | Marcus Boerger <helly@php.net> | 2003-11-27 17:06:26 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-11-27 17:06:26 +0000 |
commit | 3be27ecc78d68c2e7beccfc6eedc60e235a080c1 (patch) | |
tree | e1cbf3574b2ae4e42b9bae501d76555c491fba13 | |
parent | 7850dddf7ca30913b5c06fcc6a638bb31545f4e0 (diff) | |
download | php-git-3be27ecc78d68c2e7beccfc6eedc60e235a080c1.tar.gz |
Add a support function to check for property existance which is different
from checking a property from being empty/set.
Update test #26182.
-rw-r--r-- | Zend/zend_builtin_functions.c | 24 | ||||
-rw-r--r-- | tests/lang/bug26182.phpt | 13 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 6abbad5e6d..228e9dfaea 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -42,6 +42,7 @@ static ZEND_FUNCTION(define); static ZEND_FUNCTION(defined); static ZEND_FUNCTION(get_class); static ZEND_FUNCTION(get_parent_class); +static ZEND_FUNCTION(property_exists); static ZEND_FUNCTION(method_exists); static ZEND_FUNCTION(class_exists); static ZEND_FUNCTION(function_exists); @@ -99,6 +100,7 @@ static zend_function_entry builtin_functions[] = { ZEND_FE(defined, NULL) ZEND_FE(get_class, NULL) ZEND_FE(get_parent_class, NULL) + ZEND_FE(property_exists, NULL) ZEND_FE(method_exists, NULL) ZEND_FE(class_exists, NULL) ZEND_FE(function_exists, NULL) @@ -756,6 +758,28 @@ ZEND_FUNCTION(get_class_methods) /* }}} */ +/* {{{ proto bool property_exists(object obj, string property_name) + Checks if the object has a property */ +ZEND_FUNCTION(property_exists) +{ + zval **object, **property; + + if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &object, &property)==FAILURE) { + ZEND_WRONG_PARAM_COUNT(); + } + if ((*object)->type != IS_OBJECT) { + RETURN_FALSE; + } + + if (Z_OBJ_HANDLER_PP(object, has_property) && Z_OBJ_HANDLER_PP(object, has_property)(*object, *property, 1 TSRMLS_CC)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + + /* {{{ proto bool method_exists(object object, string method) Checks if the class method exists */ ZEND_FUNCTION(method_exists) diff --git a/tests/lang/bug26182.phpt b/tests/lang/bug26182.phpt index ec711d40c9..480d1469a0 100644 --- a/tests/lang/bug26182.phpt +++ b/tests/lang/bug26182.phpt @@ -17,6 +17,13 @@ class A { $t = new A (); print_r($t); +var_dump(property_exists($t, 'x')); +var_dump(property_exists($t, 'y')); +var_dump(property_exists($t, 'z')); +var_dump(isset($t->y)); +var_dump(property_exists($t, 'y')); +$t->z = 1; +var_dump(property_exists($t, 'z')); ?> --EXPECT-- @@ -24,3 +31,9 @@ a Object ( [x] => ) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) |