Bug #78411 [NEW]: Typed properties not working as expected when instantiated via reflection.
| From: | tandrewbennett at hotmail dot com | Date: | Tue, 13 Aug 2019 20:15:49 +0000 |
| Subject: | Bug #78411 [NEW]: Typed properties not working as expected when instantiated via reflection. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222237@lists.php.net to get a copy of this message | ||
From: tandrewbennett at hotmail dot com
Operating system: Ubuntu 16.04
PHP version: 7.4.0beta2
Package: *General Issues
Bug Type: Bug
Bug description:Typed properties not working as expected when instantiated via reflection.
Description:
------------
When instantiating an object using
reflectionClass::newInstanceWithoutConstructor, assigning values to
uninitialized typed properties has no effect.
Test script:
---------------
class Foo
{
protected string $bar;
protected string $baz;
protected string $qux = 'initial qux';
public function fillValues()
{
$this->bar = 'bar';
$this->baz = 'baz';
$this->qux = 'qux';
}
public function getBar()
{
return $this->bar;
}
public function getBaz()
{
return $this->baz;
}
public function getQux()
{
return $this->qux;
}
}
$rc = new ReflectionClass(Foo);
$foo = $rc->newInstanceWithoutConstructor();
$foo->fillValues();
echo $foo->getBar() . PHP_EOL;
echo $foo->getBaz() . PHP_EOL;
echo $foo->getQux() . PHP_EOL;
Expected result:
----------------
bar
baz
qux
Actual result:
--------------
Fatal error: Uncaught Error: Typed property Foo::$bar
must not be accessed before initialization
--
Edit bug report at https://bugs.php.net/bug.php?id=78411&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78411&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78411&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78411&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78411&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78411&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78411&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78411&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78411&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78411&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78411&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78411&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78411&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78411&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78411&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78411&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78411&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78411&r=mysqlcfg