iliaa           Fri Dec 22 15:37:49 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/reflection/tests       bug39884.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/reflection     php_reflection.c 
  Log:
  Fixed bug #39884 (ReflectionParameter::getClass() throws exception for type
  hint self).
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.453&r2=1.2027.2.547.2.454&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.453 php-src/NEWS:1.2027.2.547.2.454
--- php-src/NEWS:1.2027.2.547.2.453     Fri Dec 22 15:29:41 2006
+++ php-src/NEWS        Fri Dec 22 15:37:48 2006
@@ -19,6 +19,8 @@
 - Fixed bug #39903 (Notice message when executing __halt_compiler() more than 
   once). (Tony)
 - Fixed bug #39898 (FILTER_VALIDATE_URL validates \r\n\t etc). (Ilia)
+- Fixed bug #39884 (ReflectionParameter::getClass() throws exception for type
+  hint self). (thekid at php dot net)
 - Fixed bug #39873 (number_format() breaks with locale & decimal points).
   (Ilia)
 - Fixed bug #39869 (safe_read does not initialize errno).
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.164.2.33.2.31&r2=1.164.2.33.2.32&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.164.2.33.2.31 
php-src/ext/reflection/php_reflection.c:1.164.2.33.2.32
--- php-src/ext/reflection/php_reflection.c:1.164.2.33.2.31     Wed Oct 18 
16:35:15 2006
+++ php-src/ext/reflection/php_reflection.c     Fri Dec 22 15:37:48 2006
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.164.2.33.2.31 2006/10/18 16:35:15 johannes Exp $ 
*/
+/* $Id: php_reflection.c,v 1.164.2.33.2.32 2006/12/22 15:37:48 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1995,7 +1995,40 @@
        GET_REFLECTION_OBJECT_PTR(param);
 
        if (param->arg_info->class_name) {
-               if (zend_lookup_class(param->arg_info->class_name, 
param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) {
+               /* Class name is stored as a string, we might also get "self" 
or "parent"
+                * - For "self", simply use the function scope. If scope is 
NULL then
+                *   the function is global and thus self does not make any 
sense
+                *
+                * - For "parent", use the function scope's parent. If scope is 
NULL then
+                *   the function is global and thus parent does not make any 
sense.
+                *   If the parent is NULL then the class does not extend 
anything and
+                *   thus parent does not make any sense, either.
+                *
+                * TODO: Think about moving these checks to the compiler or 
some sort of
+                * lint-mode.
+                */
+               if (0 == strncmp(param->arg_info->class_name, "self", 
sizeof("self")- 1)) {
+                       zend_class_entry *ce= param->fptr->common.scope;
+                       if (!ce) {
+                          zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
+                                  "Parameter uses 'self' as type hint but 
function is not a class member!");
+                          return;
+                       }
+                       pce= &ce;
+               } else if (0 == strncmp(param->arg_info->class_name, "parent", 
sizeof("parent")- 1)) {
+                       zend_class_entry *ce= param->fptr->common.scope;
+                       if (!ce) {
+                          zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
+                                  "Parameter uses 'parent' as type hint but 
function is not a class member!");
+                          return;
+                       }
+                       if (!ce->parent) {
+                          zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
+                                  "Parameter uses 'parent' as type hint 
although class does not have a parent!");
+                          return;
+                       }
+                       pce= &ce->parent;
+               } else if (zend_lookup_class(param->arg_info->class_name, 
param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) {
                        zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
                                "Class %s does not exist", 
param->arg_info->class_name);
                        return;
@@ -4851,7 +4884,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Reflection", "enabled");
 
-       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 
1.164.2.33.2.31 2006/10/18 16:35:15 johannes Exp $");
+       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 
1.164.2.33.2.32 2006/12/22 15:37:48 iliaa Exp $");
 
        php_info_print_table_end();
 } /* }}} */

http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/bug39884.phpt?view=markup&rev=1.1
Index: php-src/ext/reflection/tests/bug39884.phpt
+++ php-src/ext/reflection/tests/bug39884.phpt

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

Reply via email to