[php-src] Issue #9409: Inconsistency with ReflectionMethod

From: Date: Tue, 23 Aug 2022 23:29:41 +0000
Subject: [php-src] Issue #9409: Inconsistency with ReflectionMethod
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242297@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9409 Author: KapitanOczywisty ### Description Related to #9405 and https://bugs.php.net/bug.php?id=64592 It might not be important, but I think this should be fixed at some point, so I've created a new issue. I can also provide PR if you want. 1. Private classes are accessible through child using ReflectionMethod: The following code: https://3v4l.org/Bso8B ```php <?php class A { private $privateProperty = 1; private function privateMethod() {} } class B extends A {} try { echo (string) $method = new ReflectionMethod('B', 'privateMethod'); } catch(Throwable $e){ echo (string) $e; } try { echo (string) new ReflectionProperty('B', 'privateProperty'); } catch(Throwable $e){ echo (string) $e; } ``` Resulted in this output: ``` Method [ <user, inherits A> private method privateMethod ] { @@ /in/Bso8B 6 - 6 } ReflectionException: Property B::$privateProperty does not exist in /in/Bso8B:16 Stack trace: #0 /in/Bso8B(16): ReflectionProperty->__construct('B', 'privateProperty') #1 {main} ``` But I expected this output instead: ``` ReflectionException: Method B::privateMethod() does not exist in /in/Bso8B:11 Stack trace: #0 /in/Bso8B(11): ReflectionMethod->__construct('B', 'privateMethod2') #1 {main}ReflectionException: Property B::$privateProperty does not exist in /in/Bso8B:16 Stack trace: #0 /in/Bso8B(16): ReflectionProperty->__construct('B', 'privateProperty') #1 {main} ``` 2. Child's private method is shown with overwrites A annotation, which seems to be missleading ```php <?php class A { private function privateMethod() {} } class C extends A { private function privateMethod() {} private function otherMethod() {} } $class = new ReflectionClass('C'); echo (string)$class->getMethod('privateMethod'); echo (string)$class->getMethod('otherMethod'); ``` Resulted in this output: ``` Method [ <user, overwrites A> private method privateMethod ] { @@ /in/dm3Y9 7 - 7 } Method [ <user> private method otherMethod ] { @@ /in/dm3Y9 8 - 8 } ``` But I expected this output instead: ``` Method [ <user> private method privateMethod ] { @@ /in/dm3Y9 7 - 7 } Method [ <user> private method otherMethod ] { @@ /in/dm3Y9 8 - 8 } ``` /cc @damianwadley ### PHP Version 8.0 - 8.2 ### Operating System _No response_

« previous php.bugs (#242297) next »