Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Aug 8, 2025

{
if (preg_match('/data-(\d{6})\.json$/', $s, $matches) <= 0) {
assertType('array{}', $matches);
assertType('list{0?: string, 1?: non-falsy-string&numeric-string}', $matches);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be considered as a "regression" but:

BTW array{} is already technically not true since if preg_match return false, $matches is null.

@staabm
Copy link
Contributor

staabm commented Aug 9, 2025

Ondrey wanted this problem solved via a more general approach - see #3881

@ondrejmirtes ondrejmirtes merged commit 745ae5a into phpstan:2.1.x Aug 9, 2025
448 of 453 checks passed
@ondrejmirtes
Copy link
Member

Thank you! I'd like improvements to TypeSpecifierContext but we already have many hardcoded fixes in TypeSpecifier so this is just one more. It can be refactored later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preg_match + if: false positive nullCoalesce.offset and isset.offset report an error on an array offset that can be null

3 participants