]> granicus.if.org Git - php/commitdiff
- Optional parameter to class_exists() that can be used to bypass
authorMarcus Boerger <helly@php.net>
Tue, 27 Apr 2004 18:09:40 +0000 (18:09 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 27 Apr 2004 18:09:40 +0000 (18:09 +0000)
  __autoload() which can be helpfull in __autoload() itself.

Zend/zend_builtin_functions.c

index 107d3d745ad130d37cec3e0e9db87d21827ab618..69015a6b1832eba6c2eda4d6ead201d2abd18113 100644 (file)
@@ -799,20 +799,30 @@ ZEND_FUNCTION(method_exists)
 }
 /* }}} */
 
-/* {{{ proto bool class_exists(string classname)
+/* {{{ proto bool class_exists(string classname [, bool autoload])
    Checks if the class exists */
 ZEND_FUNCTION(class_exists)
 {
-       zval **class_name;
+       char *class_name, *lc_name;
        zend_class_entry **ce;
+       long class_name_len;
+       zend_bool autoload = 1;
+       int found;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
-               ZEND_WRONG_PARAM_COUNT();
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &class_name, &class_name_len, &autoload) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(class_name);
+       if (!autoload) {
+               lc_name = do_alloca(class_name_len + 1);
+               zend_str_tolower_copy(lc_name, class_name, class_name_len);
+       
+               found = zend_hash_find(EG(class_table), lc_name, class_name_len+1, (void **) &ce);
+               free_alloca(lc_name);
+               RETURN_BOOL(found == SUCCESS);
+       }
 
-       if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &ce TSRMLS_CC) == SUCCESS) {
+       if (zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC) == SUCCESS) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;