]> granicus.if.org Git - php/commitdiff
- Fixed bug #47593 (interface_exists() returns false when using absolute namespace...
authorFelipe Pena <felipe@php.net>
Sun, 8 Mar 2009 17:23:44 +0000 (17:23 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 8 Mar 2009 17:23:44 +0000 (17:23 +0000)
  Patch by Kalle.

Zend/tests/bug47593.phpt [new file with mode: 0644]
Zend/zend_builtin_functions.c

diff --git a/Zend/tests/bug47593.phpt b/Zend/tests/bug47593.phpt
new file mode 100644 (file)
index 0000000..98aa19a
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Bug #47593 (interface_exists() returns false when using absolute namespace path)
+--FILE--
+<?php
+
+namespace test;
+const TEST = 11;
+
+class foo {
+       public function xyz() {
+       }
+}
+
+interface baz {
+}      
+
+function bar() {
+}
+
+
+var_dump(interface_exists('\test\baz'));
+var_dump(function_exists('\test\bar'));
+var_dump(constant('\test\TEST'));
+var_dump(defined('\test\TEST'));
+var_dump(defined('TEST'));
+
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+int(11)
+bool(true)
+bool(false)
index 83adda99246d92c141c1e9c728668c81fd9f48ca..c4c797dd208a145c9109f08845225c117eb137eb 100644 (file)
@@ -1230,8 +1230,24 @@ ZEND_FUNCTION(interface_exists)
        }
 
        if (!autoload) {
+               zstr name;
+               int len;
+               
                lc_name = zend_u_str_case_fold(type, iface_name, iface_name_len, 1, &lc_name_len);
-               found = zend_u_hash_find(EG(class_table), type, lc_name, lc_name_len+1, (void **) &ce);
+               
+               /* Ignore leading "\" */
+               name = lc_name;
+               len = iface_name_len;
+               if (lc_name.s[0] == '\\') {
+                       if (type == IS_UNICODE) {
+                               name.u = &lc_name.u[1];
+                       } else {
+                               name.s = &lc_name.s[1];
+                       }
+                       len--;
+               }
+               
+               found = zend_u_hash_find(EG(class_table), type, name, len+1, (void **) &ce);
                efree(lc_name.v);
                RETURN_BOOL(found == SUCCESS && (*ce)->ce_flags & ZEND_ACC_INTERFACE);
        }
@@ -1260,8 +1276,19 @@ ZEND_FUNCTION(function_exists)
        }
 
        lcname = zend_u_str_case_fold(function_name_type, function_name, function_name_len, 1, &lcname_len);
+       
+       function_name = lcname;
+       if (function_name.s[0] == '\\') {
+               if (function_name_type == IS_UNICODE) {
+                       function_name.u = &lcname.u[1];
+               } else {
+                       function_name.s = &lcname.s[1];
+               }
+               function_name_len--;
+       }
+
 
-       retval = (zend_u_hash_find(EG(function_table), function_name_type, lcname, lcname_len+1, (void **)&func) == SUCCESS);
+       retval = (zend_u_hash_find(EG(function_table), function_name_type, function_name, function_name_len+1, (void **)&func) == SUCCESS);
 
        efree(lcname.v);