ID: 46068 Comment by: andrew at linuxjedi dot co dot uk Reported By: sv4php at fmethod dot com Status: Open Bug Type: PCRE related Operating System: Windows, Linux PHP Version: 5.2.6 New Comment:
Tried in PHP 5.2.4, also tried the (?P<name>pattern) method, same problem. Previous Comments: ------------------------------------------------------------------------ [2008-09-12 19:54:10] 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" } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46068&edit=1