ID: 24539
Updated by: [EMAIL PROTECTED]
Reported By: black at scene-si dot org
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: linux debian
PHP Version: 4.3.2
New Comment:
<_Wez_> your for loop is equivalent to this:
<_Wez_> reset($data);
<_Wez_> while ($id = key($data)) {
<_Wez_> var_dump($id);
<_Wez_> next($data);
<_Wez_> }
<black|one> ... your point?
<_Wez_> $id = key($data) ==> 0 on the first iteration
<_Wez_> while (0) {
<_Wez_> }
Previous Comments:
------------------------------------------------------------------------
[2003-07-08 09:53:42] black at scene-si dot org
Description:
------------
replace key() with current() and you get the value with no problems,
key() however doesnt work.
the wierd part, sometimes the bellow code works, since i have 2
"identical" classes, one of which uses this method with key() - and
makes correct results, however this short reproducable script doesnt.
works: http://sunshine.krneki.org/files/halcyon/hal.phps
doesnt: http://sunshine.krneki.org/files/halcyon/hal2.phps
(search for 'reset', note that i have changed to use current in
hal2.phps in the update function, so check out plot() which is still
identical).
cleaning up code is sometimes a b***h ;)
Reproduce code:
---------------
$data = array("foo","bar","x","y");
for (reset($data); $id=key($data); next($data)) {
var_dump($id);
}
for (reset($data); $id=current($data); next($data)) {
var_dump($id);
}
Expected result:
----------------
int(0)
int(1)
int(2)
int(3)
string(3) "foo"
string(3) "bar"
string(1) "x"
string(1) "y"
Actual result:
--------------
string(3) "foo"
string(3) "bar"
string(1) "x"
string(1) "y"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24539&edit=1