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* return type signature #918

Merged
merged 4 commits into from Jan 11, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jan 10, 2022

No description provided.

@@ -8828,8 +8828,8 @@
'preg_filter' => ['string|array|null', 'regex'=>'string|array', 'replace'=>'string|array', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_grep' => ['array|false', 'regex'=>'string', 'input'=>'array', 'flags='=>'int'],
'preg_last_error' => ['int'],
'preg_match' => ['int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'string[]', 'flags='=>'int', 'offset='=>'int'],
'preg_match_all' => ['int|false|null', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

per https://www.php.net/preg_match_all null cannot be returned

Copy link
Member

Choose a reason for hiding this comment

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

Someone somewhere persuaded me it can return null: 0d025e7

I'll merge this if you don't remove the null type.

Copy link
Contributor Author

@staabm staabm Jan 10, 2022

Choose a reason for hiding this comment

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

added back the null type

Copy link
Contributor

Choose a reason for hiding this comment

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

In https://3v4l.org/DDBf3, I managed to make it return null on PHP 4.3

@staabm staabm changed the title more precise preg_match* return type more precise preg_match* return type signature Jan 10, 2022
@staabm
Copy link
Contributor Author

staabm commented Jan 10, 2022

ohh sorry for renaming the PR title..

resources/functionMap.php Outdated Show resolved Hide resolved
@@ -8828,8 +8828,8 @@
'preg_filter' => ['string|array|null', 'regex'=>'string|array', 'replace'=>'string|array', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_grep' => ['array|false', 'regex'=>'string', 'input'=>'array', 'flags='=>'int'],
'preg_last_error' => ['int'],
'preg_match' => ['int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'string[]', 'flags='=>'int', 'offset='=>'int'],
'preg_match_all' => ['int|false|null', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
Copy link
Member

Choose a reason for hiding this comment

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

Someone somewhere persuaded me it can return null: 0d025e7

I'll merge this if you don't remove the null type.

@ondrejmirtes ondrejmirtes merged commit 40b9368 into phpstan:master Jan 11, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the patch-3 branch January 14, 2022 16:27
@Seldaek
Copy link
Contributor

Seldaek commented Feb 17, 2022

Seems like this only works on PHP<8 for preg_match_all

See https://phpstan.org/r/ba5ee68a-c998-4a7a-bb8b-6111f03a6d1a - php8 has int|false as return value

@staabm
Copy link
Contributor Author

staabm commented Feb 17, 2022

arghs, seems I have forgotten to update the function*delta.php files.

will look into it.

@Seldaek
Copy link
Contributor

Seldaek commented Feb 17, 2022

Thanks, I can't find it in any of the delta files though, but maybe I missed something.

@staabm
Copy link
Contributor Author

staabm commented Feb 17, 2022

yep, the point is that its missing from those delta files - I guess.

@staabm
Copy link
Contributor Author

staabm commented Feb 18, 2022

fix in #1023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants