Bug #79683 [Ver->Csd]: Fake reflection scope affects __toString()

From: Date: Tue, 09 Jun 2020 13:53:30 +0000
Subject: Bug #79683 [Ver->Csd]: Fake reflection scope affects __toString()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227377@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79683&edit=1 ID: 79683 Updated by: nikic@php.net Reported by: smilimko at gmail dot com Summary: Fake reflection scope affects __toString() -Status: Verified +Status: Closed Type: Bug Package: Reflection related Operating System: Ubuntu PHP Version: 7.4.6 Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=2447fd9f84a484fbce8cd79e8e85b1fdf6ad7431 Log: Fixed bug #79683 Previous Comments: ------------------------------------------------------------------------ [2020-06-09 13:44:06] nikic@php.net Probably fake_scope leaking. ------------------------------------------------------------------------ [2020-06-09 11:46:07] smilimko at gmail dot com Description: ------------ Incorrect collaboration of the reflection, magic method __toString and typed properties. Test script: --------------- class A { private string $prop1 = '123'; public function __toString() { return $this->prop1; } } class B { private string $prop2; } $b = new B(); $reflector = new ReflectionClass($b); $property = $reflector->getProperty('prop2'); $property->setAccessible(true); $property->setValue($b, new A()); Expected result: ---------------- Property B::prop2 must have value '123'. No errors must happen. Actual result: -------------- PHP Fatal error: Uncaught Error: Cannot access private property A::$prop1 in test.php:9 Stack trace: #0 [internal function]: A->__toString() #1 test.php(23): ReflectionProperty->setValue() #2 {main} thrown in /home/sergey/www/twin.client/test.php on line 9 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79683&edit=1

« previous php.bugs (#227377) next »