|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53357 Problem with getMethod of ReflectionClass
Submitted: 2010-11-19 16:31 UTC Modified: 2010-11-21 13:05 UTC
From: jonas dot jones at gmx dot ch Assigned: johannes (profile)
Status: Not a bug Package: Reflection related
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
 [2010-11-19 16:31 UTC] jonas dot jones at gmx dot ch
From manual page:

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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-19 16:34 UTC]
-Operating System: Windows 7/all +Operating System:
 [2010-11-20 01:37 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: johannes
 [2010-11-20 01:37 UTC]
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-21 13:05 UTC]
-Status: Assigned +Status: Bogus
 [2010-11-21 13:05 UTC]
See bug #38992 for the request of passing a class name as string.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 23:01:28 2024 UTC