Req #53357 [Asn->Bgs]: Problem with getMethod of ReflectionClass

From: Date: Sun, 21 Nov 2010 12:05:31 +0000
Subject: Req #53357 [Asn->Bgs]: Problem with getMethod of ReflectionClass
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-156261@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53357&edit=1

 ID:                 53357
 Updated by:         johannes@php.net
 Reported by:        jonas dot jones at gmx dot ch
 Summary:            Problem with getMethod of ReflectionClass
-Status:             Assigned
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            Reflection related
 PHP Version:        5.3.3
 Assigned To:        johannes
 Block user comment: N
 Private report:     N

 New Comment:

See bug #38992 for the request of passing a class name as string.


Previous Comments:
------------------------------------------------------------------------
[2010-11-20 01:37:43] johannes@php.net

The reflection API is supposed to tell "the truth". Extending the
ReflectionClass::getMethod() method is therefore no option. The only
thing I can imagine is hanving ReflectionMethod::invoke() to accept a
string, instead of an instance, as first parameter for defining the
scope. I will look into that.

------------------------------------------------------------------------
[2010-11-19 16:31:22] jonas dot jones at gmx dot ch

Description:
------------
---
From manual page: http://www.php.net/reflectionclass.getmethod
---

If you use getMethod() on a ReflecitonClass Object, for a class, that
inherits its method from a parent class, you get a ReflectionMethod
Object, that links to the parent class. There is no possibility to get a
ReflectionMethod Object, that is connected to the class linked to the
ReflectionClass Object.

This beheaviour is not nice, if you want to use the ReflectionMethod
Object to call a static method. We could not figure out a possibility to
call the method on the child class.

A second argument on getMethod() would be nice. It could be a flag,
wether getMethod should return a ReflectionMethod object, which is
connected to the class where the method was defined or an object which
is connected to the class, that was used for the ReflectionClass.

Test script:
---------------
class ParentClass {
   public static function foo(){
      echo get_called_class();
   }
}
class ChildClass extends MainClass {
}

$class = new ReflectionClass('ChildClass');
$method = $class->getMethod('foo');
$method->invoke(null); // outputs ParentClass instead of expected
ChildClass

Expected result:
----------------
ChildClass

Actual result:
--------------
ParentClass


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53357&edit=1


Thread (3 messages)

« previous php.bugs (#156261) next »