|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80866 preg_split ignores limit flag when pattern with \K has 0-width fullstring match
Submitted: 2021-03-15 02:02 UTC Modified: -
From: mickmackusa at mickmack dot usa Assigned:
Status: Closed Package: PCRE related
PHP Version: 7.3.27 OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: mickmackusa at mickmack dot usa
New email:
PHP Version: OS:


 [2021-03-15 02:02 UTC] mickmackusa at mickmack dot usa
preg_split() does not respect the limit parameter when \K is used to produce a zero-width fullstring delimiter. This bug seems to be present since PHP7.3.  Other preg_split() calls using zero-width-match-producing regular expressions do not suffer the same bug.

Test script:
var_export(preg_split('~.{3}\K~', 'abcdefghijklm', 3));

Expected result:
array (
  0 => 'abc',
  1 => 'def',
  2 => 'ghijklm',

Actual result:
array (
  0 => 'abc',
  1 => 'def',
  2 => 'ghi',
  3 => 'jkl',
  4 => 'm',


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-15 12:23 UTC]
The following pull request has been associated:

Patch Name: Fix bug 80866
On GitHub:
 [2021-03-15 13:48 UTC]
Automatic comment on behalf of
Log: Fix bug #80866
 [2021-03-15 13:48 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 21:03:35 2021 UTC