From:             walter at unpleasant dot net
Operating system: Linux
PHP version:      4.3.10
PHP Bug Type:     Arrays related
Bug description:  explode() returns weird array on string that starts with 
delimiter

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 bug report at http://bugs.php.net/?id=31443&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31443&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31443&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31443&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31443&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31443&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31443&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31443&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31443&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31443&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31443&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31443&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31443&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31443&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31443&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31443&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31443&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31443&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31443&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31443&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31443&r=mysqlcfg

Reply via email to