summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>1999-12-14 21:15:24 +0000
committerAndrei Zmievski <andrei@php.net>1999-12-14 21:15:24 +0000
commit3fdf0dbedcdc4bd108079d094620dbddff627a19 (patch)
tree3e55ee521cc778bc2f896255c045da2f38fd60a9
parent7dfeb4fd21f4cae260c0b4585d074f13fccf6e75 (diff)
downloadphp-git-3fdf0dbedcdc4bd108079d094620dbddff627a19.tar.gz
- Added class_exists()
- Moved function_exists() here from from the basic_functions.c - Modified method_exists() to convert method name to lowercase when checking
-rw-r--r--Zend/zend_builtin_functions.c68
1 files changed, 63 insertions, 5 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 4e70e460a2..bbabb4d9b6 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -39,6 +39,8 @@ static ZEND_FUNCTION(defined);
static ZEND_FUNCTION(get_class);
static ZEND_FUNCTION(get_parent_class);
static ZEND_FUNCTION(method_exists);
+static ZEND_FUNCTION(class_exists);
+static ZEND_FUNCTION(function_exists);
static ZEND_FUNCTION(leak);
static ZEND_FUNCTION(get_used_files);
static ZEND_FUNCTION(get_imported_files);
@@ -60,6 +62,8 @@ static zend_function_entry builtin_functions[] = {
ZEND_FE(get_class, NULL)
ZEND_FE(get_parent_class, NULL)
ZEND_FE(method_exists, NULL)
+ ZEND_FE(class_exists, NULL)
+ ZEND_FE(function_exists, NULL)
ZEND_FE(leak, NULL)
ZEND_FE(get_used_files, NULL)
ZEND_FE(get_imported_files, NULL)
@@ -394,23 +398,77 @@ ZEND_FUNCTION(get_parent_class)
*/
ZEND_FUNCTION(method_exists)
{
- zval **arg1, **arg2;
+ zval **klass, **method_name;
+ char *lcname;
- if (ARG_COUNT(ht)!=2 || getParametersEx(2, &arg1, &arg2)==FAILURE) {
+ if (ARG_COUNT(ht)!=2 || getParametersEx(2, &klass, &method_name)==FAILURE) {
RETURN_FALSE;
}
- if ((*arg1)->type != IS_OBJECT) {
+ if ((*klass)->type != IS_OBJECT) {
RETURN_FALSE;
}
- convert_to_string_ex(arg2);
- if(zend_hash_exists(&(*arg1)->value.obj.ce->function_table, (*arg2)->value.str.val, (*arg2)->value.str.len+1)) {
+ convert_to_string_ex(method_name);
+ lcname = estrdup((*method_name)->value.str.val);
+ zend_str_tolower(lcname, (*method_name)->value.str.len);
+ if(zend_hash_exists(&(*klass)->value.obj.ce->function_table, lcname, (*method_name)->value.str.len+1)) {
+ efree(lcname);
RETURN_TRUE;
} else {
+ efree(lcname);
RETURN_FALSE;
}
}
/* }}} */
+/* {{{ proto bool class_exists(string classname)
+ Checks if the class exists ...
+*/
+ZEND_FUNCTION(class_exists)
+{
+ zval **class_name;
+ char *lcname;
+ CLS_FETCH();
+
+ if (ARG_COUNT(ht) != 1 || getParametersEx(1, &class_name)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string_ex(class_name);
+ lcname = estrdup((*class_name)->value.str.val);
+ zend_str_tolower(lcname, (*class_name)->value.str.len);
+ if (zend_hash_exists(CG(class_table), lcname, (*class_name)->value.str.len+1)) {
+ efree(lcname);
+ RETURN_TRUE;
+ } else {
+ efree(lcname);
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto bool function_exists(string function_name)
+ Checks if the function exists */
+ZEND_FUNCTION(function_exists)
+{
+ zval **function_name;
+ char *lcname;
+ CLS_FETCH();
+
+ if (ARG_COUNT(ht)!=1 || getParametersEx(1, &function_name)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(function_name);
+ lcname = estrdup((*function_name)->value.str.val);
+ zend_str_tolower(lcname, (*function_name)->value.str.len);
+ if (zend_hash_exists(CG(function_table), lcname, (*function_name)->value.str.len+1) == FAILURE) {
+ efree(lcname);
+ RETURN_FALSE;
+ } else {
+ efree(lcname);
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
ZEND_FUNCTION(leak)
{
int leakbytes=3;