note 58582 deleted from control-structures.for by danbrown
| From: | danbrown@php.net | Date: | Mon, 07 Dec 2009 16:05:54 +0000 |
| Subject: | note 58582 deleted from control-structures.for by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163653@lists.php.net to get a copy of this message | ||
Note Submitter: mbvlist at fastmail dot fm
----
While fuzzeling around with iterators (trying to find the next and previous item in a list),
discovered something odd:
<?php
for($i=0; $i < $max; $i++ && print 'increment,')
{
do_something();
echo " i = $i\n";
}
echo "finally, i = $i\n";
?>
If $max is set at 1 (only the first run will occur), it works as I expected:
i = 0
finally, i = 0
But with $max at a higher value (say 2) it works different:
i = 0
increment, i = 1
increment, finally, i = 2
After the loop was finished $i was incremented! As I read right now, this is what should happen. But
it doesn't occur in the first case. As I said, I was searching something using an iterator, and
after the loop I wanted to know the next value. Because of this 'feature' (a.k.a. bug)
that didn't work.
Be warned!