Req #63196 [Opn->Nab]: ReflectionMethod::invoke() on non-abstract ancestor
| From: | nikic@php.net | Date: | Sat, 16 Apr 2016 13:52:38 +0000 |
| Subject: | Req #63196 [Opn->Nab]: ReflectionMethod::invoke() on non-abstract ancestor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200594@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63196&edit=1
ID: 63196
Updated by: nikic@php.net
Reported by: php dot net at vdachev dot net
Summary: ReflectionMethod::invoke() on non-abstract ancestor
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: Reflection related
Operating System: Ubuntu Quantal
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
This is working as intended. ReflectionMethods refer to concrete methods, not to some concept of
"this methods or the most specific applicable override".
Previous Comments:
------------------------------------------------------------------------
[2012-10-02 08:36:05] php dot net at vdachev dot net
Description:
------------
Consider a situation when an abstract class (or an interface) is defined and a
concrete class that extends it. If we get instantiate a ReferenceClass object for
the abstract class (or the interface), we can then get an ReferenceMethod instance
for the abstract method.
Unfortunately, calling the ReferenceMethod::invoke() method for an instance of the
concrete class throws a ReflectionException ("Trying to invoke abstract
method...").
Test script:
---------------
<?php
abstract class A
{
public abstract function doA();
}
interface IB
{
function doB();
}
class B extends A implements IB
{
public function doA()
{
echo 'A is done.';
}
public function doB()
{
echo 'B is done.';
}
}
$b = new B();
$b->doA();
$b->doB();
$refA = new \ReflectionClass('A');
$refDoA = $refA->getMethod('doA');
$refDoA->invoke($b);
$refIB = new \ReflectionClass('IB');
$refDoB = $refIB->getMethod('doB');
$refDoB->invoke($b);
?>
Expected result:
----------------
The invocation of the method on an instance of the concrete class should succeed.
Actual result:
--------------
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Trying to
invoke abstract method ...()' in ...:..
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63196&edit=1