Added zend_is_callable() function that checks whether passed zval

represents a valid and exiting callable construct.
This commit is contained in:
Andrei Zmievski 2001-02-01 05:01:26 +00:00
parent f5bec86645
commit 8fe036596f
2 changed files with 41 additions and 0 deletions

View File

@ -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;
}

View File

@ -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)