|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-02-11 13:11 UTC] 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 } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
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.This actually happens on all versions, if we consider the following example <?php preg_match('/(?J)(?:(?<g>foo)|(?<g>bar))(geez)/', 'foogeez', $matches, PREG_UNMATCHED_AS_NULL); var_dump($matches); ?> Expected result: ---------------- array(5) { [0]=> string(7) "foogeez" ["g"]=> string(3) "foo" [1]=> string(3) "foo" [2]=> NULL [3]=> string(4) "geez" } Actual result: -------------- array(5) { [0]=> string(7) "foogeez" ["g"]=> string(3) "foo" [1]=> string(3) "foo" [2]=> NULL [3]=> string(4) "geez" }