diff options
author | Andrei Zmievski <andrei@php.net> | 2001-02-01 05:01:26 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2001-02-01 05:01:26 +0000 |
commit | 8fe036596f64ac30c305238ac62df6cd99b77fe7 (patch) | |
tree | 6f9ef16edd73ea4b319681cf66243f167fe7a99a | |
parent | f5bec86645de04f8bf5ca94c80f6596f9754d0db (diff) | |
download | php-git-8fe036596f64ac30c305238ac62df6cd99b77fe7.tar.gz |
Added zend_is_callable() function that checks whether passed zval
represents a valid and exiting callable construct.
-rw-r--r-- | Zend/zend_API.c | 40 | ||||
-rw-r--r-- | Zend/zend_API.h | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 02d21904ac..5ad9603e5d 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -909,3 +909,43 @@ ZEND_API int zend_disable_function(char *function_name, uint function_name_lengt disabled_function[0].fname = function_name; return zend_register_functions(disabled_function, CG(function_table), MODULE_PERSISTENT); } + +ZEND_API zend_bool zend_is_callable(zval *function) +{ + char *lcname; + zend_bool retval = 0; + ELS_FETCH(); + + switch (Z_TYPE_P(function)) { + case IS_STRING: + lcname = estrndup(Z_STRVAL_P(function), Z_STRLEN_P(function)); + zend_str_tolower(lcname, Z_STRLEN_P(function)); + if (zend_hash_exists(EG(function_table), lcname, Z_STRLEN_P(function)+1)) + retval = 1; + efree(lcname); + break; + + case IS_ARRAY: + { + zval **method; + zval **obj; + + if (zend_hash_index_find(Z_ARRVAL_P(function), 0, (void **) &obj) == SUCCESS && + zend_hash_index_find(Z_ARRVAL_P(function), 1, (void **) &method) == SUCCESS && + Z_TYPE_PP(obj) == IS_OBJECT && + Z_TYPE_PP(method) == IS_STRING) { + lcname = estrndup(Z_STRVAL_PP(method), Z_STRLEN_PP(method)); + zend_str_tolower(lcname, Z_STRLEN_PP(method)); + if (zend_hash_exists(&Z_OBJCE_PP(obj)->function_table, lcname, Z_STRLEN_PP(method)+1)) + retval = 1; + efree(lcname); + } + } + break; + + default: + break; + } + + return retval; +} diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 4759026eb7..8ae380b948 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -120,6 +120,7 @@ ZEND_API zend_module_entry *zend_get_module(int module_number); ZEND_API int zend_disable_function(char *function_name, uint function_name_length); ZEND_API void wrong_param_count(void); +ZEND_API zend_bool zend_is_callable(zval *function); #define getThis() (this_ptr) |