Skip to content

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
Development

Successfully merging this pull request may close these issues.

2 participants