php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79028 Several same-name subpatterns in distinct piped alternatives should be allowed
Submitted: 2019-12-24 17:18 UTC Modified: 2019-12-25 10:05 UTC
From: php4fan at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 7.2.26 OS:
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: php4fan at gmail dot com
New email:
PHP Version: OS:

 

 [2019-12-24 17:18 UTC] php4fan at gmail dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Ok, I see, "(?J)" modifies the behavior to accomplish what I asked for.

So, not a bug.

Sorry about the noise.
 [2019-12-25 10:05 UTC] cmb@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC