Req #68529 [NEW]: Prevent double results when using named capture groups

From: Date: Sun, 30 Nov 2014 21:03:02 +0000
Subject: Req #68529 [NEW]: Prevent double results when using named capture groups
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188858@lists.php.net to get a copy of this message
From: gooh Operating system: PHP version: Irrelevant Package: *Regular Expressions Bug Type: Feature/Change Request Bug description:Prevent double results when using named capture groups Description: ------------ When using preg_match_all with named capture groups, the result array will contain one entry with a numeric key in addition to one entry with the name of the group. Assuming I put the named capture group there on purpose, there is no reason why I would need the numeric index. It only bloats the result array. As a user I would like to have an option that returns the results without the superfluous numeric index. Test script: --------------- <?php preg_match_all( '/This message contains (?<items>[\d]+) items/', 'This message contains 42 items', $matches ); print_r($matches); Expected result: ---------------- Array ( [0] => Array ( [0] => This message contains 42 items ) [items] => Array ( [0] => 42 ) ) Actual result: -------------- Array ( [0] => Array ( [0] => This message contains 42 items ) [items] => Array ( [0] => 42 ) [1] => Array ( [0] => 42 ) ) -- Edit bug report at https://bugs.php.net/bug.php?id=68529&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68529&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68529&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68529&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68529&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68529&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68529&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68529&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68529&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68529&r=support Expected behavior: https://bugs.php.net/fix.php?id=68529&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68529&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68529&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68529&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68529&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68529&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68529&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68529&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68529&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68529&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68529&r=mysqlcfg

« previous php.bugs (#188858) next »