Skip to content

Commit 2c0f488

Browse files
committed
Disallow PREG_SET_ORDER in matchAll
1 parent 68be757 commit 2c0f488

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Preg.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Preg
2626
public static function match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
2727
{
2828
if (($flags & PREG_OFFSET_CAPTURE) !== 0) {
29-
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches');
29+
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchWithOffset() instead');
3030
}
3131

3232
$result = preg_match($pattern, $subject, $matches, $flags, $offset);
@@ -70,7 +70,11 @@ public static function matchWithOffset($pattern, $subject, &$matches = null, $fl
7070
public static function matchAll($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
7171
{
7272
if (($flags & PREG_OFFSET_CAPTURE) !== 0) {
73-
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches');
73+
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use matchAllWithOffset() instead');
74+
}
75+
76+
if (($flags & PREG_SET_ORDER) !== 0) {
77+
throw new \InvalidArgumentException('PREG_SET_ORDER is not supported as it changes the type of $matches');
7478
}
7579

7680
$result = preg_match_all($pattern, $subject, $matches, $flags, $offset);

src/Regex.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function isMatch($pattern, $subject, $offset = 0)
3434
public static function match($pattern, $subject, $flags = 0, $offset = 0)
3535
{
3636
if (($flags & PREG_OFFSET_CAPTURE) !== 0) {
37-
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type');
37+
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type, use matchWithOffset() instead');
3838
}
3939

4040
$count = Preg::match($pattern, $subject, $matches, $flags, $offset);
@@ -68,7 +68,11 @@ public static function matchWithOffset($pattern, $subject, $flags = 0, $offset =
6868
public static function matchAll($pattern, $subject, $flags = 0, $offset = 0)
6969
{
7070
if (($flags & PREG_OFFSET_CAPTURE) !== 0) {
71-
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type');
71+
throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type, use matchAllWithOffset() instead');
72+
}
73+
74+
if (($flags & PREG_SET_ORDER) !== 0) {
75+
throw new \InvalidArgumentException('PREG_SET_ORDER is not supported as it changes the return type');
7276
}
7377

7478
$count = Preg::matchAll($pattern, $subject, $matches, $flags, $offset);

0 commit comments

Comments
 (0)