]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #47593 (interface_exists() returns false when using absolute namespa...
authorFelipe Pena <felipe@php.net>
Sun, 8 Mar 2009 17:28:39 +0000 (17:28 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 8 Mar 2009 17:28:39 +0000 (17:28 +0000)
  patch by Kalle
- BFN #47572

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

diff --git a/NEWS b/NEWS
index 7bd100b62472059a8cd8f100a593699d3524a6ba..9371a042a3c998df55be460cc6f541177956b058 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ PHP                                                                        NEWS
 
 - Re-enabled phar for big-endian systems after fixing problems. (Greg)
 
+- Fixed bug #47593 (interface_exists() returns false when using absolute 
+  namespace path). (Kalle, Felipe)
+- Fixed bug #47572 (Undefined constant causes segmentation fault). (Felipe)
 - Fixed bug #47549 (get_defined_constants() return array with broken
   array categories). (Ilia)
 - Fixed Bug #47443 (metaphone('scratch') returns wrong result). (Felipe)
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 f7d0dc99605355b700328db0c197a1fcbe4cfbb2..3dbd0805103077739a9fb85306c0923f8924b1c2 100644 (file)
@@ -1228,10 +1228,21 @@ ZEND_FUNCTION(interface_exists)
        }
 
        if (!autoload) {
+               char *name;
+               int len;
+               
                lc_name = do_alloca(iface_name_len + 1, use_heap);
                zend_str_tolower_copy(lc_name, iface_name, iface_name_len);
        
-               found = zend_hash_find(EG(class_table), lc_name, iface_name_len+1, (void **) &ce);
+               /* Ignore leading "\" */
+               name = lc_name;
+               len = iface_name_len;
+               if (lc_name[0] == '\\') {
+                       name = &lc_name[1];
+                       len--;
+               }
+
+               found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce);
                free_alloca(lc_name, use_heap);
                RETURN_BOOL(found == SUCCESS && (*ce)->ce_flags & ZEND_ACC_INTERFACE);
        }
@@ -1260,8 +1271,15 @@ ZEND_FUNCTION(function_exists)
        }
 
        lcname = zend_str_tolower_dup(name, name_len);
+       
+       /* Ignore leading "\" */
+       name = lcname;
+       if (lcname[0] == '\\') {
+               name = &lcname[1];
+               name_len--;
+       }
 
-       retval = (zend_hash_find(EG(function_table), lcname, name_len+1, (void **)&func) == SUCCESS);
+       retval = (zend_hash_find(EG(function_table), name, name_len+1, (void **)&func) == SUCCESS);
        
        efree(lcname);