Bug #79257 [Com]: Duplicate named groups ((?J) modifier) broken since 7.4
| From: | ptomulik at meil dot pw dot edu dot pl | Date: | Tue, 11 Feb 2020 16:13:52 +0000 |
| Subject: | Bug #79257 [Com]: Duplicate named groups ((?J) modifier) broken since 7.4 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225496@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79257&edit=1
ID: 79257
Comment by: ptomulik at meil dot pw dot edu dot pl
Reported by: ptomulik at meil dot pw dot edu dot pl
Summary: Duplicate named groups ((?J) modifier) broken since
7.4
Status: Verified
Type: Bug
Package: PCRE related
Operating System: Debian/Ubuntu
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
Looks like the actual problem existed in 7.3 and earlier, but it required slight modification to be
reproduced. I'll try to update the bug report to take it into account.
Previous Comments:
------------------------------------------------------------------------
[2020-02-11 15:41:26] nikic@php.net
Parts of this actually also seem broken on earlier versions, for example:
preg_match('/(?J)(?:(?<g>foo)|(?<g>bar))(?<h>baz)/', 'foobaz',
$matches);
var_dump($matches);
array(6) {
[0]=>
string(6) "foobaz"
["g"]=>
string(0) ""
[1]=>
string(3) "foo"
[2]=>
string(0) ""
["h"]=>
string(3) "baz"
[3]=>
string(3) "baz"
}
Key "g" should be "foo" here though.
------------------------------------------------------------------------
[2020-02-11 13:11:21] ptomulik at meil dot pw dot edu dot pl
Description:
------------
It appears, that the "backward incompatible changes" in PHP7.4 - "Regular
Expressions", as described here:
https://www.php.net/manual/en/migration74.incompatible.php
affect named capture groups when duplicate names are enabled ((?J) modifier/PCRE2_DUPMANES config).
In 7.4 named capture group always returns the content captured in last alternative, no matter which
of the alternatives matched. This differs from 7.3 and renders DUPNAMES feature useless.
Test script:
---------------
<?php
preg_match('/(?J)(?:(?<g>foo)|(?<g>bar))/', 'foo', $matches,
PREG_UNMATCHED_AS_NULL);
var_dump($matches);
?>
Expected result:
----------------
array(4) {
[0]=>
string(3) "foo"
["g"]=>
string(3) "foo"
[1]=>
string(3) "foo"
[2]=>
NULL
}
Actual result:
--------------
array(4) {
[0]=>
string(3) "foo"
["g"]=>
NULL
[1]=>
string(3) "foo"
[2]=>
NULL
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79257&edit=1