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

False positive errors with number_format function #7158

Closed
ChrisGalliano opened this issue Dec 14, 2021 · 2 comments · Fixed by #7159
Closed

False positive errors with number_format function #7158

ChrisGalliano opened this issue Dec 14, 2021 · 2 comments · Fixed by #7159

Comments

@ChrisGalliano
Copy link

https://psalm.dev/r/b86432a24c

<?php
  echo number_format(10.363, 1, thousands_separator: " ");

->

ERROR: InvalidNamedArgument - 3:31 - Parameter $thousands_separator does not exist on function number_format
ERROR: TooManyArguments - 3:6 - Too many arguments for number_format - expecting 2 but saw 3

number_format function signature (https://www.php.net/manual/ru/function.number-format.php):

number_format(
    float $num,
    int $decimals = 0,
    ?string $decimal_separator = ".",
    ?string $thousands_separator = ","
): string
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b86432a24c
<?php

echo number_format(10.363, 1, thousands_separator: " ");
Psalm output (using commit 832fc35):

ERROR: InvalidNamedArgument - 3:31 - Parameter $thousands_separator does not exist on function number_format

ERROR: TooManyArguments - 3:6 - Too many arguments for number_format - expecting 2 but saw 3

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Dec 14, 2021

Working on this, the simple fix is fairly easy, number_format was just a bit weird before PHP 8.0.

AndrolGenhald added a commit to AndrolGenhald/psalm that referenced this issue Dec 14, 2021
@orklah orklah linked a pull request Dec 14, 2021 that will close this issue
orklah added a commit that referenced this issue Dec 14, 2021
…onal-arguments

Fix optional arguments in number_format (fixes #7158).
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 a pull request may close this issue.

2 participants