From: gtg782a at mail dot gatech dot edu
Operating system: RH 7.3
PHP version: 5.1.2
PHP Bug Type: Strings related
Bug description: str_split returns non-empty array when given empty string as
argument
Description:
------------
In the lastest version of PHP (5.1.2), running str_split with an empty
string returns an array containing a single element, which is also an
empty string. This seems counterintuitive and is a different result than
in previous versions of PHP5. Rather than return a single-element array
with an empty string, I would expect an empty array with no elements.
(5.0.4 evaluates in the latter way - giving the more intuitive result).
This makes a difference when the resulting array is used as the argument
to foreach, for example, such as foreach(str_split($string) as $letter).
If a string is empty, it would be intuitive that foreach would never
execute its inner code.
If this is an intended behavior, then the version difference ought to be
noted in the documentation. I do think, however, that the old behavior
made more sense.
Reproduce code:
---------------
var_dump(str_split(""));
Expected result:
----------------
array(0) { }
Actual result:
--------------
array(1) { [0]=> string(0) "" }
--
Edit bug report at http://bugs.php.net/?id=37048&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37048&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=37048&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37048&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37048&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37048&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37048&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37048&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37048&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37048&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37048&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37048&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37048&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37048&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37048&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37048&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37048&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37048&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37048&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37048&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37048&r=mysqlcfg