|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-06-09 13:44 UTC] nikic@php.net
-Status: Open
+Status: Verified
[2020-06-09 13:44 UTC] nikic@php.net
[2020-06-09 13:49 UTC] nikic@php.net
-Summary: Strange behaviour of typed properties
+Summary: Fake reflection scope affects __toString()
[2020-06-09 13:53 UTC] nikic@php.net
[2020-06-09 13:53 UTC] nikic@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 12:00:01 2025 UTC |
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