php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63196 ReflectionMethod::invoke() on non-abstract ancestor
Submitted: 2012-10-02 08:36 UTC Modified: 2016-04-16 13:52 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php dot net at vdachev dot net Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.7 OS: Ubuntu Quantal
Private report: No CVE-ID: None
 [2012-10-02 08:36 UTC] 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 ...:..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-16 13:52 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2016-04-16 13:52 UTC] nikic@php.net
This is working as intended. ReflectionMethods refer to concrete methods, not to some concept of "this methods or the most specific applicable override".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 01 12:01:22 2020 UTC