php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9265 passing preg_split a limit parameter of 0 supresses all matches
Submitted: 2001-02-14 16:33 UTC Modified: 2001-02-19 14:31 UTC
From: chuck at horde dot org Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.0 Latest CVS (14/02/2001) OS: Linux 2.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chuck at horde dot org
New email:
PHP Version: OS:

 

 [2001-02-14 16:33 UTC] chuck at horde dot org
Somewhere in the last few weeks, preg_split changed so that specifiying a limit parameter of 0 returns the string to be split unchanged. Before that, 0 was seemingly treated as no limit, meaning that you could safely specify 0 as the limit argument in order to specify a flag as the fourth argument.

<?php

$foo = 'a|b|c|d';
$m = preg_split('/|/', $foo, 0);

var_dump($m);

?>

will return everything in the same array, whereas if the limit argument is left off (or increased), the string gets split up. The behavior allowing 0 to be no limit should be returned, or another safe argument for limit that means no limit documented.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-19 14:31 UTC] andrei@php.net
As far as I remember, 0 has never meant "no limit" - the value for that is -1. But the documentation does need to be updated.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Mar 13 21:01:32 2025 UTC