jani                                     Sat, 01 Aug 2009 01:45:22 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=286611

Log:
- Fixed bug #49092 (ReflectionFunction fails to work with functions in fully 
qualified namespaces)

Bug: http://bugs.php.net/49092 (Open) ReflectionFunction fails to work with 
functions in fully qualified namespaces
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
    A   php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49092.phpt
    U   php/php-src/trunk/ext/reflection/php_reflection.c
    A   php/php-src/trunk/ext/reflection/tests/bug49092.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2009-08-01 01:44:09 UTC (rev 286610)
+++ php/php-src/branches/PHP_5_3/NEWS   2009-08-01 01:45:22 UTC (rev 286611)
@@ -8,6 +8,8 @@
 - Fixed signature generation/validation for zip archives in ext/phar. (Greg)
 - Fixed memory leak in stream_is_local(). (Felipe)

+- Fixed bug #49092 (ReflectionFunction fails to work with functions in fully
+  qualified namespaces). (Kalle, Jani)
 - Fixed bug #49074 (private class static fields can be modified by using
   reflection). (Jani)
 - Fixed bug #49108 (2nd scan_dir produces seg fault). (Felipe)

Modified: php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c        
2009-08-01 01:44:09 UTC (rev 286610)
+++ php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c        
2009-08-01 01:45:22 UTC (rev 286611)
@@ -1516,8 +1516,18 @@
                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, "s", 
&name_str, &name_len) == SUCCESS) {
+               char *nsname;
+
                lcname = zend_str_tolower_dup(name_str, name_len);
-               if (zend_hash_find(EG(function_table), lcname, name_len + 1, 
(void **)&fptr) == FAILURE) {
+
+               /* Ignore leading "\" */
+               nsname = lcname;
+               if (lcname[0] == '\\') {
+                       nsname = &lcname[1];
+                       name_len--;
+               }
+
+               if (zend_hash_find(EG(function_table), nsname, name_len + 1, 
(void **)&fptr) == FAILURE) {
                        efree(lcname);
                        zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC,
                                "Function %s() does not exist", name_str);

Added: php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49092.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49092.phpt             
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49092.phpt     
2009-08-01 01:45:22 UTC (rev 286611)
@@ -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

Modified: php/php-src/trunk/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/trunk/ext/reflection/php_reflection.c   2009-08-01 01:44:09 UTC 
(rev 286610)
+++ php/php-src/trunk/ext/reflection/php_reflection.c   2009-08-01 01:45:22 UTC 
(rev 286611)
@@ -1523,8 +1523,22 @@
                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);

Added: php/php-src/trunk/ext/reflection/tests/bug49092.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/bug49092.phpt                        
        (rev 0)
+++ php/php-src/trunk/ext/reflection/tests/bug49092.phpt        2009-08-01 
01:45:22 UTC (rev 286611)
@@ -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

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to