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

Improve sscanf() signature #567

Merged
merged 8 commits into from Jul 7, 2021
Merged

Improve sscanf() signature #567

merged 8 commits into from Jul 7, 2021

Conversation

fluffycondor
Copy link
Contributor

If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.

If there are more substrings expected in the format than there are available within string, null will be returned.

https://www.php.net/manual/en/function.sscanf.php

 If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.

If there are more substrings expected in the format than there are available within string, null will be returned. 

https://www.php.net/manual/en/function.sscanf.php
@ondrejmirtes
Copy link
Member

Can you please test in NodeScopeResolverTest that your change does what you think it does? Thanks!

@fluffycondor
Copy link
Contributor Author

Can you please test in NodeScopeResolverTest that your change does what you think it does? Thanks!

Done.

@@ -11546,7 +11546,8 @@
'sqlsrv_server_info' => ['array', 'conn'=>'resource'],
'sqrt' => ['float', 'number'=>'float'],
'srand' => ['void', 'seed='=>'int', 'mode='=>'int'],
'sscanf' => ['mixed', 'str'=>'string', 'format'=>'string', '&...w_vars='=>'string|int|float|null'],
'sscanf' => ['int|null', 'str'=>'string', 'format'=>'string', '&...w_vars'=>'string|int|float|null'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ondrejmirtes I have no idea why the tests fails, can you help me?
I made variadic args not optional, but I still get array|int|null for two-arguments signature, but I want just array|null.

Copy link
Member

Choose a reason for hiding this comment

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

This is why I wanted you to write these tests because I wasn't sure it's going to work the way you want. You need to modify the signature so that there's a third required parameter (non-variadic), and the fourth one is variadic and optional.

@ondrejmirtes ondrejmirtes merged commit d50aa7d into phpstan:master Jul 7, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@fluffycondor fluffycondor deleted the sscanf_signature_fix branch July 7, 2021 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants