Bug #79683 [NEW]: Strange behaviour of typed properties
| From: | smilimko at gmail dot com | Date: | Tue, 09 Jun 2020 11:46:07 +0000 |
| Subject: | Bug #79683 [NEW]: Strange behaviour of typed properties | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227374@lists.php.net to get a copy of this message | ||
From: smilimko at gmail dot com
Operating system: Ubuntu
PHP version: 7.4.6
Package: Reflection related
Bug Type: Bug
Bug description:Strange behaviour of typed properties
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 bug report at https://bugs.php.net/bug.php?id=79683&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79683&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79683&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79683&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79683&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79683&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79683&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79683&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79683&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79683&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79683&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79683&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79683&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79683&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79683&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79683&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79683&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79683&r=mysqlcfg