-
Notifications
You must be signed in to change notification settings - Fork 7.8k
str_split
must return empty array for empty string
#8924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Wouldn't it actually be the correct solution instead if both Splitting a string is supposed to return an array of the string's characters. An empty string has zero characters, so the expected and logical result would be an empty array (that is, an array containing zero characters). When splitting a string, it should hold that |
When This commit changed it, but this obviously was an unintended (and also undocumented) side effect. The commit claims to be a performance optimization only, while in fact it was a functional change: the commit author simply didn't correctly consider the case when the input string is empty. All later PHP versions built upon this change, and so the current It would of course be a breaking change to fix |
As a final note, the current documentation also claims
which obviously isn't true. |
👍, that "optimization commit" should be fixed. Then it would be consistent also with |
mb_str_split
must return one empty element for empty stringstr_split
must return empty array for empty string
I tend to agree that this is a bug (although one that should not be fixed in a revision), and not merely a documentation issue. |
Co-authored-by: Christoph M. Becker <[email protected]>
Co-authored-by: Christoph M. Becker <[email protected]>
Description
The following code:
https://3v4l.org/1WsGi
Resulted in but I expected this output instead:
Array ( - [0] => ) Array ( ) Array ( ) Array ( ) Array ( )
I belive this is an inconsistency that should be fixed.
The inconsistency was introduced in 0818fae by a mistake as found out by @emkey08 in the discussion below.
PHP Version
PHP 7.4 - master
Operating System
any
The text was updated successfully, but these errors were encountered: