Skip to content

Commit f596950

Browse files
committed
Update preg_match_shapes.php
1 parent ca7703e commit f596950

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/PHPStan/Analyser/nsrt/preg_match_shapes.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function (string $size): void {
300300
if (preg_match('~^a\.(b)?(c)?d~', $size, $matches) !== 1) {
301301
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
302302
}
303-
assertType("array{0: string, 1?: 'b', 2?: 'c'}", $matches);
303+
assertType("array{0: string, 1?: ''|'b', 2?: 'c'}", $matches);
304304
};
305305

306306
function (string $size): void {
@@ -662,3 +662,24 @@ function (string $value): void
662662
assertType("array{0: array{string, int<0, max>}, 1?: array{non-empty-string, int<0, max>}, 2?: array{non-empty-string, int<0, max>}}", $matches);
663663
}
664664
};
665+
666+
class Bug11479
667+
{
668+
static public function sayHello(string $source): void
669+
{
670+
$pattern = "~^(?P<dateFrom>\d)?\-?(?P<dateTo>\d)?$~";
671+
672+
preg_match($pattern, $source, $matches);
673+
674+
// for $source = "-1" in $matches is
675+
// array (
676+
// 0 => '-1',
677+
// 'dateFrom' => '',
678+
// 1 => '',
679+
// 'dateTo' => '1',
680+
// 2 => '1',
681+
//)
682+
683+
assertType("array{0?: string, dateFrom?: ''|numeric-string, 1?: ''|numeric-string, dateTo?: numeric-string, 2?: numeric-string}", $matches);
684+
}
685+
}

0 commit comments

Comments
 (0)