|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79683 Fake reflection scope affects __toString()
Submitted: 2020-06-09 11:46 UTC Modified: 2020-06-09 13:49 UTC
From: smilimko at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.4.6 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: smilimko at gmail dot com
New email:
PHP Version: OS:


 [2020-06-09 11:46 UTC] smilimko at gmail dot com
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->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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-09 13:44 UTC]
-Status: Open +Status: Verified
 [2020-06-09 13:44 UTC]
Probably fake_scope leaking.
 [2020-06-09 13:49 UTC]
-Summary: Strange behaviour of typed properties +Summary: Fake reflection scope affects __toString()
 [2020-06-09 13:53 UTC]
Automatic comment on behalf of
Log: Fixed bug #79683
 [2020-06-09 13:53 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 13:01:32 2024 UTC