php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34876 preg_split should return empty array when splitting ""
Submitted: 2005-10-14 22:12 UTC Modified: 2005-10-18 22:14 UTC
From: embeddedlinuxguy at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: embeddedlinuxguy at gmail dot com
New email:
PHP Version: OS:

 

 [2005-10-14 22:12 UTC] embeddedlinuxguy at gmail dot com
Description:
------------
$b = preg_split("/q/", "", PREG_SPLIT_NO_EMPTY);

should return an empty array (0 elements).  Instead it returns an array with one element which is an empty string, i.e. ("").  This is the same with or without PREG_SPLIT_NO_EMPTY.

Compare to Perl

my @a = split(/q/, "");

Here @a == () not ("")



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-18 22:14 UTC] embeddedlinuxguy at gmail dot com
Oops, I should have used
preg_split("/q/", "", -1, PREG_SPLIT_NO_EMPTY);
which works.

If preg_split is supposed to be Perl Compatible (as in PCRE) then this behavior ought to be changed to match Perl's split() by default:

By default, empty leading fields are preserved, and empty trailing ones are deleted.  (If all fields are empty, they are considered to be trailing.)

Not sure if this is a PHP bug, a PCRE bug, or a feature.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 06:01:28 2024 UTC