php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46068 Incorrently reported PCRE / PREG regex named pattern
Submitted: 2008-09-12 19:54 UTC Modified: 2008-09-12 20:09 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sv4php at fmethod dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.6 OS: Windows, Linux
Private report: No CVE-ID: None
 [2008-09-12 19:54 UTC] sv4php at fmethod dot com
Description:
------------
Under certain circumstanced, the $matches in a preg_match contain the wrong name of a named subpattern. Refer to the example below.

Note the conditions:

1. The named patterns have the same numeric index (as they are in a switch group:  (?| .. | .. | .. ) ).
2. The last name alphabetically is always reported, never mind of the pattern order and the actual pattern matched ('zoo' is last after 'poo', 'hoo' alphabetically in the example below).

Reproduced on Linux and Windows.

Reproduce code:
---------------
$c = 'yo';
$p = '/(?|(?<poo>yo)|(?<hoo>fo)|(?<zoo>ho))/';
preg_match ($p, $c, $m);
var_dump($m);

Expected result:
----------------
array(3) {
  [0]=>
  string(2) "yo"
  ["poo"]=>      <-- notice the name
  string(2) "yo"
  [1]=>
  string(2) "yo"
}

Actual result:
--------------
array(3) {
  [0]=>
  string(2) "yo"
  ["zoo"]=>      <-- notice the name
  string(2) "yo"
  [1]=>
  string(2) "yo"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-12 20:01 UTC] andrew at linuxjedi dot co dot uk
Tried in PHP 5.2.4, also tried the (?P<name>pattern) method, same problem.
 [2008-09-12 20:09 UTC] scottmac@php.net
I can reproduce this with PCRE 7.8, you need to report this upstream to them.

http://bugs.exim.org/enter_bug.cgi?product=PCRE
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 19:01:31 2024 UTC