[php-src] Issue #8545: Acquiring a reference to uninitialized typed property when iterating over object properties doesn't throw
| From: | iluuu1994 | Date: | Fri, 13 May 2022 09:48:42 +0000 |
| Subject: | [php-src] Issue #8545: Acquiring a reference to uninitialized typed property when iterating over object properties doesn't throw | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241473@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8545
Author: iluuu1994
### Description
The following code:
https://3v4l.org/EKvdF
```php
<?php
class Test {
public $a;
public int $b;
}
$test = new Test;
foreach ($test as $prop => &$value) {
$value = 42;
}
var_dump($test);
```
Resulted in this output:
```
object(Test)#1 (1) {
["a"]=>
&int(42)
["b"]=>
uninitialized(int)
}
```
But I expected this output instead:
```
Fatal error: Uncaught Error: Cannot access uninitialized non-nullable property Test::$b by reference
```
### PHP Version
PHP 8.1.6
### Operating System
Fedora 36