preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call
未关闭
还没有人认领这个 Issue。
Extension: pcre
Feature
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php // preg_match_all.php
$matches = [0 => 'Orange',
1 => 'Apple',
2 => 'Banana',
3 => 'Monkey'];
$result = preg_match_all('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);
$result = preg_match('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);
Resulted in this output from command line %php preg_match_all.php:
PHP Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
array(4) {
[0] =>
string(6) "Orange"
[1] =>
string(5) "Apple"
[2] =>
string(6) "Banana"
[3] =>
string(6) "Monkey"
}
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
array(4) {
[0] =>
string(6) "Orange"
[1] =>
string(5) "Apple"
[2] =>
string(6) "Banana"
[3] =>
string(6) "Monkey"
}
But I expected this output instead:
PHP Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
either: null or array[0]
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
either: null or array[0]
PHP Version
PHP 7.4.27
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 PHP 7.4.27 上使用无效模式重现提供的 preg_match() 和 preg_match_all() 调用,然后在 PHP 解释器中跟踪这两个 API。完成的标准是,匹配失败后不再使调用者之前的 $matches 内容保持不变,并为两个函数提供回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100