Skip to content
Browse files

- Fixed bug #49092 (ReflectionFunction fails to work with functions i…

…n fully qualified namespaces)
  • Loading branch information...
1 parent 0b03346 commit adf8f72f14707bf1096ac94f1b26133b039b2c84 Jani Taskinen committed Aug 1, 2009
Showing with 25 additions and 1 deletion.
  1. +2 −0 NEWS
  2. +11 −1 ext/reflection/php_reflection.c
  3. +12 −0 ext/reflection/tests/bug49092.phpt
View
2 NEWS
@@ -8,6 +8,8 @@ PHP NEWS
- 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)
View
12 ext/reflection/php_reflection.c
@@ -1516,8 +1516,18 @@ 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, "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);
View
12 ext/reflection/tests/bug49092.phpt
@@ -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

0 comments on commit adf8f72

Please sign in to comment.
Something went wrong with that request. Please try again.