[php-src] Issue #9006: Suport null coalescing operator and error control operator in Array destructuring to prevent PHP warning "undefined array key"
e.g. used in foreach
| From: | laukstein | Date: | Wed, 13 Jul 2022 19:35:28 +0000 |
| Subject: | [php-src] Issue #9006: Suport null coalescing operator and error control operator in Array destructuring to prevent PHP warning "undefined array key" e.g. used in foreach |
||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241921@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9006
Author: laukstein
### Description
Array destructuring was added in PHP 7.1. It seems missing null coalescing and error control
operator and leads stuck with undefined array keys warings without ability to workaround it when
arrays may miss some keys.
Example
```
$data = [
['id' => 1],
['id' => 2, 'name' => 'PHP']
];
foreach ($data as ['id' => $id, 'name' => $name]) {}
```
will return **Warning : Undefined array key "name"**.
Please support null coalescing operator
```
foreach ($data as ['id' => $id, 'name' => $name ?? null]) {}
```
and error control operator
```
foreach ($data as @['id' => $id, 'name' => $name]) {}
```
to workaround this PHP incapability and get rid with those warings.