note 126744 added to migration70.incompatible
| From: | Alexis at AmasisGr | Date: | Mon, 03 Jan 2022 13:31:54 +0000 |
| Subject: | note 126744 added to migration70.incompatible | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217461@lists.php.net to get a copy of this message | ||
Another important change in foreach that is not reported,
is that it also changed the way by-reference is handled.
You can no longer replace the item of the iteration by reference.
For example
<?php
$a = [
['id' => '1001'],
['id' => '190']
];
foreach ($a ?: [] as &$b) {
$b = [
'id' => $b['id'],
'text' => $b['id'],
];
}
var_export($a);
-----
PHP 5 result:
array (
0 =>
array (
'id' => '1001',
'text' => '1001',
),
1 =>
array (
'id' => '190',
'text' => '190',
),
)
-----
PHP >=7 result:
array (
0 =>
array (
'id' => '1001',
),
1 =>
array (
'id' => '190',
),
)
This might seem trivial, but it broke my code.
This might seem bad practice, but for whatever reason
we have code like this. And I can see how it makes sense
in some cases
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 2a02:587:4915:12c9:a9bc:2a30:44ec:357b)
----
Manual Page -- https://php.net/manual/en/migration70.incompatible.php
Edit -- https://main.php.net/note/edit/126744
Del: integrated -- https://main.php.net/note/delete/126744/integrated
Del: useless -- https://main.php.net/note/delete/126744/useless
Del: bad code -- https://main.php.net/note/delete/126744/bad+code
Del: spam -- https://main.php.net/note/delete/126744/spam
Del: non-english -- https://main.php.net/note/delete/126744/non-english
Del: in docs -- https://main.php.net/note/delete/126744/in+docs
Del: other reasons-- https://main.php.net/note/delete/126744
Reject -- https://main.php.net/note/reject/126744
Search -- https://main.php.net/manage/user-notes.php