Bug #79683 [Opn->Ver]: Strange behaviour of typed properties
| From: | nikic@php.net | Date: | Tue, 09 Jun 2020 13:44:06 +0000 |
| Subject: | Bug #79683 [Opn->Ver]: Strange behaviour of typed properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227375@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: Strange behaviour of typed properties
-Status: Open
+Status: Verified
Type: Bug
Package: Reflection related
Operating System: Ubuntu
PHP Version: 7.4.6
Block user comment: N
Private report: N
New Comment:
Probably fake_scope leaking.
Previous Comments:
------------------------------------------------------------------------
[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