|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-12 14:50 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 14 13:00:02 2025 UTC |
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) "" }