Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more precise preg_match_all return type on php8 #1023

Merged
merged 1 commit into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/functionMap_php80delta.php
Expand Up @@ -85,6 +85,7 @@
'PhpToken::is' => ['bool', 'kind'=>'string|int|string[]|int[]'],
'PhpToken::isIgnorable' => ['bool'],
'PhpToken::getTokenName' => ['string'],
'preg_match_all' => ['0|positive-int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', 'process'=>'resource'],
'set_error_handler' => ['?callable', 'callback'=>'null|callable(int,string,string,int):bool', 'error_types='=>'int'],
'socket_addrinfo_lookup' => ['AddressInfo[]', 'node'=>'string', 'service='=>'mixed', 'hints='=>'array'],
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -722,6 +722,12 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/callable-in-union.php');
}

if (PHP_VERSION_ID < 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php7.php');
} else {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php8.php');
}

require_once __DIR__ . '/data/countable.php';
yield from $this->gatherAssertTypes(__DIR__ . '/data/countable.php');

Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/data/preg_match_php7.php
@@ -0,0 +1,12 @@
<?php

namespace PregMatch;

use function PHPStan\Testing\assertType;

class Foo {
public function doFoo() {
assertType('0|1|false', preg_match('{}', ''));
assertType('int<0, max>|false|null', preg_match_all('{}', ''));
}
}
13 changes: 13 additions & 0 deletions tests/PHPStan/Analyser/data/preg_match_php8.php
@@ -0,0 +1,13 @@
<?php

namespace PregMatch;

use function PHPStan\Testing\assertType;

class Foo {
public function doFoo() {
assertType('0|1|false', preg_match('{}', ''));
assertType('int<0, max>|false', preg_match_all('{}', ''));

}
}