ID:               31443
 User updated by:  walter at unpleasant dot net
 Reported By:      walter at unpleasant dot net
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Linux
 PHP Version:      4.3.10
 New Comment:

Pardon me, it seems my brain had an out of coffee error.


Previous Comments:
------------------------------------------------------------------------

[2005-01-07 21:05:53] [EMAIL PROTECTED]

You should try 'var_dump()' sometimes..
>From manual:

"reset() rewinds array's internal pointer to the first element and
returns the value of the first array element"

First element in the array you get from the string which starts with
the delimeter is...tada..EMPTY!

"" == FALSE but FALSE !== ""

In other words: use === to compare reliably..

NO bug here.


------------------------------------------------------------------------

[2005-01-07 20:11:21] walter at unpleasant dot net

Description:
------------
When explode() explodes a string that starts with the delimiter, it
returns an array that confuses reset(). The array is not empty, but
reset()ing it returns FALSE.

The same thing happens with split().

This messes up when you try to iterate over the result like this:

for($i = reset($array);$i;$i = next($array) { ... }



Reproduce code:
---------------
$array = split(',', ',a,b,c');
echo count($array) . "Count is \n";
if(reset($array) == FALSE) echo "Can't happen.\n";


Expected result:
----------------
If I understand the semantics of reset() correctly, it should only
returns FALSE on empty arrays. The array above is clearly not empty
(count($array) returns 4), so resetting it should not return FALSE.


Actual result:
--------------
The above script prints out this when run:

Count is 4
Can't happen.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31443&edit=1

Reply via email to