Bug #64592 [Opn->Nab]: ReflectionClass::getMethods() returns methods out of scope
| From: | felipe@php.net | Date: | Sat, 06 Apr 2013 15:27:46 +0000 |
| Subject: | Bug #64592 [Opn->Nab]: ReflectionClass::getMethods() returns methods out of scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178324@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64592&edit=1
ID: 64592
Updated by: felipe@php.net
Reported by: benjamin dot morel at gmail dot com
Summary: ReflectionClass::getMethods() returns methods out of
scope
-Status: Open
+Status: Not a bug
Type: Bug
Package: Reflection related
Operating System: Linux
PHP Version: 5.4.13
Block user comment: N
Private report: N
New Comment:
It is not intended to just show the accessible ones, hence we already have introduced method like
ReflectionMethod::setAccessible().
Previous Comments:
------------------------------------------------------------------------
[2013-04-06 15:11:19] benjamin dot morel at gmail dot com
Works like a charm with your patch, thanks!
Any chance that gets into 5.4, or at least 5.5 (if there is a fear of breaking BC
with existing libraries that would rely on this behaviour)?
------------------------------------------------------------------------
[2013-04-06 13:19:41] laruence@php.net
The following patch has been added/updated:
Patch Name: bug64592.patch
Revision: 1365254381
URL: https://bugs.php.net/patch-display.php?bug=64592&patch=bug64592.patch&revision=1365254381
------------------------------------------------------------------------
[2013-04-06 11:54:57] benjamin dot morel at gmail dot com
But at least, getMethods() and getProperties() should behave in the same way,
shouldn't they?
------------------------------------------------------------------------
[2013-04-06 02:08:02] laruence@php.net
for php, even the private inherited function is not "visible", but it exists in
the child function table.
------------------------------------------------------------------------
[2013-04-05 16:14:30] benjamin dot morel at gmail dot com
Description:
------------
As far as I understand it, ReflectionClass::getMethods() should return only the
methods that are in the scope of the reflected class, thus excluding private
methods from parent classes.
That's moreover the behaviour exposed by ReflectionClass::getProperties(), making
the two methods behave in different manners.
Test script:
---------------
class Foo {
private $a;
private function a() {}
protected $b;
protected function b() {}
}
class Bar extends Foo {
private $c;
private function c() {}
}
$r = new ReflectionClass('Bar');
echo 'Properties in scope: ';
foreach ($r->getProperties() as $property) {
echo $property->getName() . ' ';
}
echo PHP_EOL, 'Methods in scope: ';
foreach ($r->getMethods() as $method) {
echo $method->getName() . ' ';
}
Expected result:
----------------
Properties in scope: c b
Methods in scope: c b
Actual result:
--------------
Properties in scope: c b
Methods in scope: c a b
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64592&edit=1