|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-12-24 17:36 UTC] php4fan at gmail dot com
-Status: Open
+Status: Closed
[2019-12-24 17:36 UTC] php4fan at gmail dot com
[2019-12-25 10:05 UTC] cmb@php.net
-Status: Closed
+Status: Not a bug
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 22:00:01 2025 UTC |
Description: ------------ see below test script and expected and observed behavior below. Maybe this an issue at the level of regular expressions specifications. As I only use them in PHP, I don't know, so I report it here. Also, it's so evidently flawed that maybe PHP could implement them correctly anyway while waiting for the specs to be fixed; not sure about that. Test script: --------------- <?php $content = <<<'HERE' First match: foo::"XYZ" Second match: bar--<XYZ> HERE; $content=preg_replace_callback('#foo::"(?<sub>[^"]*)"|bar--<(?<sub>[^>]*)>#', 'testReplace', $content); function testReplace($match) { print_r($match); return 'XXX'; } Expected result: ---------------- Array ( [0] => foo::"XYZ" [sub] => XYZ [1] => XYZ ) Array ( [0] => bar--<XYZ> [1] => [sub] => XYZ [2] => XYZ ) Actual result: -------------- Warning: preg_replace_callback(): Compilation failed: two named subpatterns have the same name Because the subgroups with the same name appear on two sides of a "|", there should be no conflict. At most one of the piped patterns (i.e. either side of the "|") can match, they are mutually exclusive, so there is no ambiguity possible and it should be a problem that a subgroup appear in both of them with the same name, as it can only be assigned once anyway.