iliaa           Fri Dec 22 15:38:42 2006 UTC

  Modified files:              
    /php-src/ext/reflection/tests       bug39884.phpt 
    /php-src/ext/reflection     php_reflection.c 
  Log:
  MFB: Fixed bug #39884 (ReflectionParameter::getClass() throws exception for
  type hint self).  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/bug39884.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/reflection/tests/bug39884.phpt
diff -u /dev/null php-src/ext/reflection/tests/bug39884.phpt:1.2
--- /dev/null   Fri Dec 22 15:38:42 2006
+++ php-src/ext/reflection/tests/bug39884.phpt  Fri Dec 22 15:38:42 2006
@@ -0,0 +1,22 @@
+--TEST--
+Bug #39884 (ReflectionParameter::getClass() throws exception for type hint 
self)
+--FILE--
+<?php
+class stubParamTest
+{
+    function paramTest(self $param)
+    {
+        // nothing to do
+    }
+}
+$test1 = new stubParamTest();
+$test2 = new stubParamTest();
+$test1->paramTest($test2);
+$refParam = new ReflectionParameter(array('stubParamTest', 'paramTest'), 
'param');
+var_dump($refParam->getClass());
+?>
+--EXPECT--     
+object(ReflectionClass)#4 (1) {
+  ["name"]=>
+  string(13) "stubParamTest"
+}
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.268&r2=1.269&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.268 
php-src/ext/reflection/php_reflection.c:1.269
--- php-src/ext/reflection/php_reflection.c:1.268       Tue Dec 19 21:38:59 2006
+++ php-src/ext/reflection/php_reflection.c     Fri Dec 22 15:38:42 2006
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.268 2006/12/19 21:38:59 andrei Exp $ */
+/* $Id: php_reflection.c,v 1.269 2006/12/22 15:38:42 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -2009,7 +2009,41 @@
        GET_REFLECTION_OBJECT_PTR(param);
 
        if (param->arg_info->class_name.v) {
-               if (zend_u_lookup_class_ex(UG(unicode)?IS_UNICODE:IS_STRING, 
param->arg_info->class_name, param->arg_info->class_name_len, 1, 1, &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.v, "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.v, 
"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_u_lookup_class_ex(UG(unicode)?IS_UNICODE:IS_STRING, 
param->arg_info->class_name, param->arg_info->class_name_len, 1, 1, &pce 
TSRMLS_CC) == FAILURE) {
                        zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
                                "Class %v does not exist", 
param->arg_info->class_name);
                        return;
@@ -4948,7 +4982,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.268 
2006/12/19 21:38:59 andrei Exp $");
+       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.269 
2006/12/22 15:38:42 iliaa Exp $");
 
        php_info_print_table_end();
 } /* }}} */

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

Reply via email to