]> granicus.if.org Git - php/commitdiff
Changed is_a() and is_subcalls_of() functions to not call __autoload() (in the same...
authorDmitry Stogov <dmitry@php.net>
Tue, 23 Aug 2005 07:23:30 +0000 (07:23 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 23 Aug 2005 07:23:30 +0000 (07:23 +0000)
NEWS
Zend/tests/is_a.phpt [new file with mode: 0755]
Zend/zend_builtin_functions.c
Zend/zend_execute.h
Zend/zend_execute_API.c

diff --git a/NEWS b/NEWS
index 4fd3e8301e054b34d2d217ff507b6affad86a1be..239f0e9ab1fd9e1c15b14d7b94a7242737507367 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,8 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 6.0
 - Unicode support. (Andrei, Dmitriy, et al)
-- Changed "instanceof" operator to not call __autoload(). (Dmitry)
+- Changed "instanceof" operator, is_a() and is_subcalls_of() functions to not
+  call __autoload(). (Dmitry)
 - cURL improvements: (Ilia)
   . Added curl_setopt_array() which allows setting of multiple cURL options.
   . Added CURLINFO_HEADER_OUT to facilitate request retrieval.
diff --git a/Zend/tests/is_a.phpt b/Zend/tests/is_a.phpt
new file mode 100755 (executable)
index 0000000..20daf5a
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+is_a() and is_subclass_of() shouldn't call __autoload
+--INI--
+error_reporting=4095
+--FILE--
+<?php
+function __autoload($name) {
+       echo("AUTOLOAD '$name'\n");
+       eval("class $name {}");
+}
+
+class BASE {
+}
+
+interface INT {
+}
+
+class A extends BASE implements INT {
+}
+
+$a = new A;
+var_dump(is_a($a, "B1"));
+var_dump(is_a($a, "A"));
+var_dump(is_a($a, "BASE"));
+var_dump(is_a($a, "INT"));
+var_dump(is_subclass_of($a, "B2"));
+var_dump(is_subclass_of($a, "A"));
+var_dump(is_subclass_of($a, "BASE"));
+var_dump(is_subclass_of($a, "INT"));
+?>
+--EXPECTF--
+Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %sis_a.php on line 17
+bool(false)
+
+Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %sis_a.php on line 18
+bool(true)
+
+Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %sis_a.php on line 19
+bool(true)
+
+Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %sis_a.php on line 20
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+bool(false)
index a54da0ee4faaebed2a725a555d651796af731467..41dbada57a006350fa44973013a71d5ebe2e5339 100644 (file)
@@ -674,7 +674,7 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass)
 
        convert_to_text_ex(class_name);
 
-       if (zend_u_lookup_class(Z_TYPE_PP(class_name), Z_UNIVAL_PP(class_name), Z_UNILEN_PP(class_name), &ce TSRMLS_CC) == FAILURE) {
+       if (zend_u_lookup_class_ex(Z_TYPE_PP(class_name), Z_UNIVAL_PP(class_name), Z_UNILEN_PP(class_name), 0, &ce TSRMLS_CC) == FAILURE) {
                retval = 0;
        } else {
                if (only_subclass) {
index ad05ea771906e4c49127d5b2ba1ffe104e8d9c09..40e09203aec49037dea946c71c8d13456d15ed98 100644 (file)
@@ -66,6 +66,7 @@ static inline void safe_free_zval_ptr_rel(zval *p ZEND_FILE_LINE_DC ZEND_FILE_LI
 }
 ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***ce TSRMLS_DC);
 ZEND_API int zend_u_lookup_class(zend_uchar type, void *name, int name_length, zend_class_entry ***ce TSRMLS_DC);
+ZEND_API int zend_u_lookup_class_ex(zend_uchar type, void *name, int name_length, int use_autoload, zend_class_entry ***ce TSRMLS_DC);
 ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC);
 ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
 ZEND_API int zend_u_eval_string(zend_uchar type, void *str, zval *retval_ptr, char *string_name TSRMLS_DC);
index 0c70d9ee16631bbbd181be4c39923ce34437d7b7..233dbfe3c04e071c92032cecdfa8c007386c765c 100644 (file)
@@ -973,7 +973,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
 }
 
 
-ZEND_API int zend_u_lookup_class(zend_uchar type, void *name, int name_length, zend_class_entry ***ce TSRMLS_DC)
+ZEND_API int zend_u_lookup_class_ex(zend_uchar type, void *name, int name_length, int use_autoload, zend_class_entry ***ce TSRMLS_DC)
 {
        zval **args[1];
        zval autoload_function;
@@ -1001,7 +1001,7 @@ ZEND_API int zend_u_lookup_class(zend_uchar type, void *name, int name_length, z
        /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
         * (doesn't impact fuctionality of __autoload()
        */
-       if (zend_is_compiling(TSRMLS_C)) {
+       if (!use_autoload || zend_is_compiling(TSRMLS_C)) {
                efree(lc_name);
                return FAILURE;
        }
@@ -1073,6 +1073,11 @@ ZEND_API int zend_u_lookup_class(zend_uchar type, void *name, int name_length, z
        return retval;
 }
 
+ZEND_API int zend_u_lookup_class(zend_uchar type, void *name, int name_length, zend_class_entry ***ce TSRMLS_DC)
+{
+       return zend_u_lookup_class_ex(type, name, name_length, 1, ce TSRMLS_CC);
+}
+
 ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***ce TSRMLS_DC)
 {
        return zend_u_lookup_class(IS_STRING, name, name_length, ce TSRMLS_CC);
@@ -1429,7 +1434,7 @@ void zend_unset_timeout(TSRMLS_D)
 ZEND_API zend_class_entry *zend_u_fetch_class(zend_uchar type, void *class_name, uint class_name_len, int fetch_type TSRMLS_DC)
 {
        zend_class_entry **pce;
-       zend_bool use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
+       int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
 
        fetch_type = fetch_type & ~ZEND_FETCH_CLASS_NO_AUTOLOAD;
 check_fetch_type:
@@ -1456,26 +1461,17 @@ check_fetch_type:
                        break;
        }
 
-       if (use_autoload) {
-               if (zend_u_lookup_class(type, class_name, class_name_len, &pce TSRMLS_CC)==FAILURE) {
+       if (zend_u_lookup_class_ex(type, class_name, class_name_len, use_autoload, &pce TSRMLS_CC)==FAILURE) {
+               if (use_autoload) {
                        if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
                                zend_error(E_ERROR, "Interface '%R' not found", type, class_name);
                        } else {
                                zend_error(E_ERROR, "Class '%R' not found", type, class_name);
                        }
                }
-               return *pce;
+               return NULL;
        } else {
-               unsigned int lc_name_len;
-               void *lc_name = zend_u_str_case_fold(type, class_name, class_name_len, 1, &lc_name_len);
-
-               if (zend_u_hash_find(EG(class_table), type, lc_name, lc_name_len+1, (void **) &pce) == SUCCESS) {
-                       efree(lc_name);
-                       return *pce;
-               } else {
-                       efree(lc_name);
-                       return NULL;
-               }
+               return *pce;
        }
 }