Doc #68457 [Com]: Reference by pointer inaccurate in foreach
| From: | gabri dot ns at gmail dot com | Date: | Thu, 20 Nov 2014 02:07:08 +0000 |
| Subject: | Doc #68457 [Com]: Reference by pointer inaccurate in foreach | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11676@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68457&edit=1
ID: 68457
Comment by: gabri dot ns at gmail dot com
Reported by: mberding at dtoolbox dot com
Summary: Reference by pointer inaccurate in foreach
Status: Not a bug
Type: Documentation Problem
Package: Variables related
Operating System: CentOS
PHP Version: 5.4.35
Block user comment: N
Private report: N
New Comment:
there is nothing wrong with foreach documentation, it is @mberding lack of understanding of
reference that cause this, and i think it is because reference documentation where placed far below.
since reference is about variable, why don't place it right after?
i think its a good thing.
Previous Comments:
------------------------------------------------------------------------
[2014-11-20 01:42:42] yohgaki@php.net
http://3v4l.org/ui7LJ
The last element became usual var with unset(), though. Separate zval after foreach by default,
parhaps?
------------------------------------------------------------------------
[2014-11-20 01:35:46] yohgaki@php.net
Or is it possible not to change the last element of the input array a reference?
It would be the best behavior.
http://3v4l.org/QSZXm
According this result, all elements became reference until 5.2.0 which is consistent for elements.
Current behavior is inconsistent, it seems.
------------------------------------------------------------------------
[2014-11-20 01:27:59] yohgaki@php.net
Sample code in the doc may be improved.
I didn't understand what's going on at first.
http://3v4l.org/jNfvt
<?php
$a = array(1,2,3,4);
foreach($a AS &$y) {
$y = $y*2;
}
echo PHP_EOL;
var_dump($a);
foreach($a AS $y) {
echo $y.' ';
}
echo PHP_EOL;
var_dump($a);
------------------------------------------------------------------------
[2014-11-20 01:20:54] yohgaki@php.net
I got it. I works as it documented ;)
http://3v4l.org/eH1NY
------------------------------------------------------------------------
[2014-11-19 23:15:49] yohgaki@php.net
I'm missing something probably, but this result is interesting to me.
http://3v4l.org/G2fXg
http://3v4l.org/CCadi
I don't have time to look into now :)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=68457
--
Edit this bug report at https://bugs.php.net/bug.php?id=68457&edit=1