Bug #81369 [Nab]: Private and protected methods are called as public!

From: Date: Tue, 17 Aug 2021 13:03:18 +0000
Subject: Bug #81369 [Nab]: Private and protected methods are called as public!
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235906@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81369&edit=1 ID: 81369 Updated by: nikic@php.net Reported by: mail at zabmix dot ru Summary: Private and protected methods are called as public! Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 7.3.29 Block user comment: N Private report: N New Comment: Yes, using reflection should work. Or you can use closure rebinding to simulate a call as if it happened from a different scope (e.g. global scope). Previous Comments: ------------------------------------------------------------------------ [2021-08-17 12:45:01] mail at zabmix dot ru How can I get around this and only use methods that are public? Use ReflectionMethod for validation? ------------------------------------------------------------------------ [2021-08-17 12:35:33] nikic@php.net __call() is invoked for inaccessible methods. The methods you call are accessible from the __call() scope, so they succeed. ------------------------------------------------------------------------ [2021-08-17 12:12:39] mail at zabmix dot ru If you call a non-existent method, the script will start to occupy all memory echo $my->test(); ------------------------------------------------------------------------ [2021-08-17 12:07:32] mail at zabmix dot ru Description: ------------ Any method properties are ignored when called inside a __call function. Test script: --------------- class One { protected function cat() { return 'this is cat'; } } class Two extends One { private function dog() { return 'this is dog'; } public function __call($name, array $args = []) { return call_user_func_array([new Three, $name], $args) . PHP_EOL; } } class Three extends Two { public function bird() { return 'this is bird'; } } $my = new Two(); echo $my->cat(); echo $my->dog(); echo $my->bird(); Expected result: ---------------- I expect at least a scoping error ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81369&edit=1

« previous php.bugs (#235906) next »