php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39104 ReflectionClass::getMethod and private method
Submitted: 2006-10-10 05:15 UTC Modified: 2006-10-13 11:28 UTC
From: dave at dgx dot cz Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.2.0RC5 OS:
Private report: No CVE-ID: None
 [2006-10-10 05:15 UTC] dave at dgx dot cz
Description:
------------
I'd to like to see 5.2 as first version of PHP, where Reflection works correctly ;-)) 

1) ReflectionProperty::getDeclaringClass works good, ReflectionMethod::getDeclaringClass doesn't. 

class Foo {
  // ReflectionProperty test
  public $prop;

  protected function a() {}
  protected static function b() {}
  public function c() {}
  public static function d() {}
}

class Extended extends Foo {
  // redeclare all members
  public $prop;
  protected function a() {}
  protected static function b() {}
  public function c() {}
  public static function d() {}
}

$rc = new ReflectionClass('Extended');
// prints Foo - OK!
echo $rc->getProperty('prop')->getDeclaringClass()->getName();

// prints Extended - ERROR
echo $rc->getMethod('a')->getDeclaringClass()->getName();
echo $rc->getMethod('b')->getDeclaringClass()->getName();
echo $rc->getMethod('c')->getDeclaringClass()->getName();
echo $rc->getMethod('d')->getDeclaringClass()->getName();


2) there still remains bug #37964: Reflection shows private methods of parent class. Private AND/OR private static 

class Foo {
  private function a() {}
  private static function b() {}
}

class Extended extends Foo {
// there is no method a() or b() in class Extended
}

Extended::b(); // this produces fatal error, OK

$rc = new ReflectionClass('Extended');
$rc->hasMethod('a');  // but this returns TRUE - ERROR

// and this works too, but shouldn't
echo $rc->getMethod('a')->getName();
echo $rc->getMethod('b')->getName();



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-10 08:53 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-10-10 09:52 UTC] dave at dgx dot cz
The behaviour is still the same.
 [2006-10-10 10:44 UTC] tony2001@php.net
Expected behaviour.
 [2006-10-10 10:51 UTC] dave at dgx dot cz
Expected??

1)

ReflectionProperty::getDeclaringClass()->getName() -> Foo
ReflectionMethod::getDeclaringClass()->getName() -> Extended

Both property and method are declared in Foo and redeclared in Extended.

2) How can I detect that private method is declared in reflected class, and not in any parent class?
 [2006-10-13 10:45 UTC] tony2001@php.net
>ReflectionProperty::getDeclaringClass()->getName() -> Foo
>ReflectionMethod::getDeclaringClass()->getName() -> Extended

>Both property and method are declared in Foo and
>redeclared in Extended.
There is no difference whether a public property was declared in the parent or in the child - in both cases it exists in the lists of properties of both classes.
And there is a big difference if a public method gets redeclared, because it would be executed in the scope of the class where it was executed.
This scope is used as the "declaring class".
So it is expected, yes.

The second problem is assigned to me, no need to create another report about it.
 [2006-10-13 11:28 UTC] dave at dgx dot cz
> And there is a big difference if a public method gets redeclared, because it would be executed in the scope of the class where it was executed.

Thank you for explain Tony, it makes sense.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC