]> granicus.if.org Git - php/commitdiff
- Fixed bug #49092 (ReflectionFunction fails to work with functions in fully qualifie...
authorJani Taskinen <jani@php.net>
Sat, 1 Aug 2009 01:45:22 +0000 (01:45 +0000)
committerJani Taskinen <jani@php.net>
Sat, 1 Aug 2009 01:45:22 +0000 (01:45 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug49092.phpt [new file with mode: 0644]

index d6973307bb739e3ab02b361e27471b5641b18c7f..8f3e6be392b0bb462bac66cf076f49c511b639b3 100644 (file)
@@ -1523,8 +1523,22 @@ ZEND_METHOD(reflection_function, __construct)
                fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC);
                Z_ADDREF_P(closure);
        } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &name_str, &name_len, &type) == SUCCESS) {
+               zstr nsname;
+
                lcname = zend_u_str_case_fold(type, name_str, name_len, 1, &lcname_len);
-               if (zend_u_hash_find(EG(function_table), type, lcname, lcname_len + 1, (void **)&fptr) == FAILURE) {
+
+               /* Ignore leading "\" */
+               nsname = lcname;
+               if (lcname.s[0] == '\\') {
+                       if (type == IS_UNICODE) {
+                               nsname.u = &lcname.u[1];
+                       } else {
+                               nsname.s = &lcname.s[1];
+                       }
+                       lcname_len--;
+               }
+
+               if (zend_u_hash_find(EG(function_table), type, nsname, lcname_len + 1, (void **)&fptr) == FAILURE) {
                        efree(lcname.v);
                        zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
                                "Function %R() does not exist", type, name_str);
diff --git a/ext/reflection/tests/bug49092.phpt b/ext/reflection/tests/bug49092.phpt
new file mode 100644 (file)
index 0000000..460a131
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #49092 (ReflectionFunction fails to work with functions in fully qualified namespaces)
+--FILE--
+<?php
+namespace ns;
+function func(){}
+new \ReflectionFunction('ns\func');
+new \ReflectionFunction('\ns\func');
+echo "Ok\n"
+?>
+--EXPECT--
+Ok