Bug #72688 [Ana->Csd]: preg_match missing group names in matches

From: Date: Wed, 27 Jul 2016 17:15:15 +0000
Subject: Bug #72688 [Ana->Csd]: preg_match missing group names in matches
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202642@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72688&edit=1 ID: 72688 Updated by: cmb@php.net Reported by: konrad dot baumgart at moneyhouse dot de Summary: preg_match missing group names in matches -Status: Analyzed +Status: Closed Type: Bug Package: PCRE related Operating System: Ubuntu 16.04 PHP Version: 7.0.9 Assigned To: cmb Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmb Revision: http://git.php.net/?p=php-src.git;a=commit;h=315c0536c20619478fc548b782132cd65286018f Log: Fix #72688: preg_match missing group names in matches Previous Comments: ------------------------------------------------------------------------ [2016-07-27 16:36:14] cmb@php.net Confirmed: <https://3v4l.org/sJWmA>. The solution is simple: we have to multiply by 0x100 instead of 0xff to construct a 16bit value[1]. Anyhow, the expected result would be: bool(true) bool(true) bool(true) string(3) "290" string(0) NULL see <https://3v4l.org/5CR74>. [1] <https://github.com/php/php-src/blob/PHP-7.0.9/ext/pcre/php_pcre.c#L264> ------------------------------------------------------------------------ [2016-07-27 15:19:11] konrad dot baumgart at moneyhouse dot de Description: ------------ When I create many named groups in pattern like \(?'group0'foo)|(?'group1'bar)|…\ then the resulting $matches does not show 'group254'. What was supposed to be in $matches['group254'] is in $matches['group255'], and so on. the lack repeats every ~255 named groups and the offset is getting worse and worse. I tested it on php 7 and php 5.5, locally and in online-php-sandbox. Test script: --------------- <?php $pattern = []; for ($i = 0; $i < 300; $i++) { $pattern[] = "(?'group{$i}'{$i}$)"; } $fullPattern = '/' . implode('|', $pattern) . '/uix'; preg_match($fullPattern, '290', $matches); var_dump(isset($matches['group253'])); var_dump(isset($matches['group254'])); var_dump(isset($matches['group255'])); var_dump($matches['group290']); var_dump($matches['group291']); Expected result: ---------------- bool(true) bool(true) bool(true) string(3) "290" string(0) "" Actual result: -------------- bool(true) bool(false) bool(true) string(0) "" string(3) "290" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72688&edit=1

« previous php.bugs (#202642) next »