php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40223 ReflectionMethod is not an subclass of ReflectionFunction
Submitted: 2007-01-24 19:39 UTC Modified: 2007-03-25 10:39 UTC
From: baldurien at bbnwn dot eu Assigned:
Status: Closed Package: Documentation problem
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2007-01-24 19:39 UTC] baldurien at bbnwn dot eu
Description:
------------
The doc (http://fr.php.net/manual/en/language.oop5.reflection.php) state that ReflectioMethod be a ReflectionFunction.

class ReflectionFunction implements Reflector { }
class ReflectionMethod extends ReflectionFunction { }

But this is not how it works in PHP : when using type hinting, any ReflectionMethod passed to a function or method that expect a ReflectionFunction fails instead of working like with normal type hinting.

Reproduce code:
---------------
class Foo {
  public function bar(ReflectionFunction $fct)  {
    ...
  }
}
$c = new ReflectionClass('Foo');
$foo = new Foo();
$foo->bar($c->getMethod('bar'));

Expected result:
----------------
This should work because ReflectionMethod is a sub class of a ReflectionFunction, and type hinting normally allows such thing (or the documentation [http://fr.php.net/manual/en/language.oop5.typehinting.php] should say it clearly...)

Actual result:
--------------
[E_RECOVERABLE_ERROR] Argument 1 passed to Foo::bar() must be an instance of ReflectionFunction, instance of ReflectionMethod given, called in ... on line ... and defined' in ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-24 19:46 UTC] bjori@php.net
(reclassified as documentation problem)

The docs are wrong (and really outdated).

ReflectionMethod and ReflectionFunction both extend 
ReflectionFunctionAbstract.

(see: php --rc ReflectionMethod && php --rc 
ReflectionFunction or php --re reflection)
 [2007-01-24 19:47 UTC] tony2001@php.net
The documentation is wrong, both ReflectionMethod & ReflectionFunction extend abstract class called "ReflectionFunctionAbstract".
 [2007-01-24 20:23 UTC] helly@php.net
Method and Functions are in no way derived. Thus the following design approach was taken:

class ReflectionMethod extends ReflectionFunctionAbstract implements Reflector

class ReflectionFunction extends ReflectionFunctionAbstract implements Reflector
 [2007-03-25 10:39 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

class ReflectionFunction extends ReflectionFunctionAbstract implements Reflector { }
class ReflectionMethod extends ReflectionFunctionAbstract implements Reflector { }

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 03:01:29 2024 UTC