Date: 11/30/02
- Next message: Gabor Hojtsy: "Re: [PHP-DOC] cvs: phpdoc /entities global.ent"
- Previous message: pollita <email protected>: "[PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- In reply to: pollita <email protected>: "[PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Next in thread: Gabor Hojtsy: "Re: [PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Reply: Gabor Hojtsy: "Re: [PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Please don't close assigned bugs, I was working on this.
On 30 Nov 2002 pollita <email protected> wrote:
> ID: 8353
> Updated by: pollita <email protected>
> Reported By: lunepi <email protected>
> -Status: Open
> +Status: Closed
> Bug Type: Documentation problem
> PHP Version: 4.4.0-dev
> Assigned To: philip
> New Comment:
>
> This bug has been fixed in CVS.
>
> In case this was a PHP problem, snapshots of the sources are packaged
> every three hours; this change will be in the next snapshot. You can
> grab the snapshot at http://snaps.php.net/.
>
> In case this was a documentation problem, the fix will show up soon at
> http://www.php.net/manual/.
>
> In case this was a PHP.net website problem, the change will show
> up on the PHP.net site and on the mirror sites in short time.
>
> Thank you for the report, and for helping us make PHP better.
>
> Modified Note re: "Works on a Copy"
>
>
> Previous Comments:
> ------------------------------------------------------------------------
>
> [2002-11-28 11:42:45] philip <email protected>
>
> The foreach() page will be updated and made more clear on this
> behavior. Regarding the pointer, foreach() indeed behaves like
> while/each() (except for the initial reset) and moves the pointer past
> the end. So although it provides a copy to work with it still affects
> the original arrays pointer!
>
> ------------------------------------------------------------------------
>
> [2002-11-27 10:32:33] philip <email protected>
>
> As I've been taught, foreach doesn't affect the pointer as it merely
> works on a copy. Also, the following note exists in the foreach()
> entry of the manual and has for over two years:
>
> Note: Also note that foreach operates on a copy of the specified
> array, not the array itself, therefore the array pointer is not
> modified as with the each() construct and changes to the array element
> returned are not reflected in the original array.
>
> That was added by Sterling here:
>
> http://cvs.php.net/diff.php/phpdoc/en/language/control-structures.xml?login=2&r1=1.9&r2=1.10&ty=h
>
> Everyone assumes foreach works on a copy and only a copy. IMHO each()
> isn't a fair comparison because it doesn't work on a copy.
>
> ------------------------------------------------------------------------
>
> [2002-11-24 23:10:40] iliaa <email protected>
>
> IMO this is not a bug. Foreach works virtually like while + each
> combination, with a few exceptions such as not requiring a reset()
> prior to execution since it does not care about the current position in
> the array.
> As far as current(), next() and simular are concerned,
> while (each($arr)); == foreach ($arr as $v);, once the loops are
> complete current() will return FALSE. This IMO is a consistent
> behaviour and is definately not a bug. I believe this is merely a
> documentation issue.
>
> ------------------------------------------------------------------------
>
> [2002-11-21 15:21:34] philip <email protected>
>
> foreach essentially REMOVES the array pointer alltogether on the
> original array.
>
> $arr = array('a','b'); foreach ($arr as $v); var_dump( current($arr)
> );
> $arr = array('a','b'); foreach ($arr as $v); reset($arr); var_dump(
> current($arr) );
>
> Results:
> bool(false)
> string(1) "a"
>
> Using key() instead of current() results in NULL instead of false.
> Where did the pointer go?
>
> Conclusion:
> Either foreach() has a feature that removes the array pointer from the
> original array or it's a bug. If it's seen as a feature please explain
> why so it can be documented.
>
> ------------------------------------------------------------------------
>
> [2001-03-09 21:32:57] sniper <email protected>
>
> no feedback.
>
>
> ------------------------------------------------------------------------
>
> 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
> http://bugs.php.net/8353
>
> --
> Edit this bug report at http://bugs.php.net/?id=8353&edit=1
>
>
> --
> PHP Documentation Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: Gabor Hojtsy: "Re: [PHP-DOC] cvs: phpdoc /entities global.ent"
- Previous message: pollita <email protected>: "[PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- In reply to: pollita <email protected>: "[PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Next in thread: Gabor Hojtsy: "Re: [PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Reply: Gabor Hojtsy: "Re: [PHP-DOC] #8353 [Opn->Csd]: foreach modify array pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

