note 126744 deleted from migration70.incompatible by cmb

From: Date: Mon, 03 Jan 2022 14:27:40 +0000
Subject: note 126744 deleted from migration70.incompatible by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217462@lists.php.net to get a copy of this message
Note Submitter: Alexis @ Amasis Gr ---- 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

« previous php.notes (#217462) next »