Skip to content

Commit

Permalink
Fix preg_match_all stub (vimeo#4325)
Browse files Browse the repository at this point in the history
* preg_match_all can return false

* Test for preg_match_all returning false

* Fix test

* Add @psalm-ignore-falsable-return
  • Loading branch information
Synchro authored and danog committed Jan 29, 2021
1 parent d4ccfcf commit fb505df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stubs/CoreGenericFunctions.phpstub
Expand Up @@ -760,7 +760,8 @@ function preg_replace_callback($search, $replace, $subject, int $limit = -1, &$c
* )
* )
* ) $matches
* @return int
* @return int|false
* @psalm-ignore-falsable-return
*/
function preg_match_all($pattern, $replace, &$matches = [], int $flags = 1, int $offset = 0) {}

Expand Down
9 changes: 9 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -1341,6 +1341,15 @@ function foo(string $input): array {
return $matches[0];
}'
],
'pregMatchAllReturnsFalse' => [
'<?php
/**
* @return int|false
*/
function badpattern() {
return @preg_match_all("foo", "foo", $matches);
}'
],
'strposAllowDictionary' => [
'<?php
function sayHello(string $format): void {
Expand Down

0 comments on commit fb505df

Please sign in to comment.