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

Too few arguments in SprintfFunctionDynamicReturnTypeExtension #2342

Closed
stepanets opened this issue Jul 31, 2019 · 6 comments
Closed

Too few arguments in SprintfFunctionDynamicReturnTypeExtension #2342

stepanets opened this issue Jul 31, 2019 · 6 comments
Labels
Milestone

Comments

@stepanets
Copy link

Bug report

When analyzing code like this:
$sql = sprintf('UPDATE {{%loans}} SET field=1');
i get
Warning: sprintf(): Too few arguments in /var/www/html/vendor/phpstan/phpstan/src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php on line 39
in console during progress run

/var/www/html # vendor/bin/phpstan analyze --memory-limit=2G -c phpstan.neon


Warning: sprintf(): Too few arguments in /var/www/html/vendor/phpstan/phpstan/src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php on line 39
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

изображение

Code snippet that reproduces the problem

$sql = sprintf('UPDATE {{%loans}} SET field=1');

PHPStan - PHP Static Analysis Tool 0.11.12

parameters:
    level: max
    reportMagicProperties: false
    autoload_files:
        - %rootDir%/../../yiisoft/yii2/Yii.php

PHP 7.1.30 (cli) (built: Jun 18 2019 00:54:58) ( NTS )

Expected output

without warnings

@mergeable
Copy link

mergeable bot commented Jul 31, 2019

This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 31, 2019

Yes, this is a bug, thanks. Also, the wrong sprintf should be picked up by the rule but isn't:

@staabm
Copy link
Contributor

staabm commented Dec 3, 2022

I tried reproducing the reported warning on php 7.4 (since phpstan no longer 7.1 which is the one the OP used).
I also tested on php 8.1.
Can't reproduce the warning using phpstan/phpstan-src@0f1bfb5, maybe it was fixed in the meantime.

I cannot test on 7.2 with my setup.


regarding the argument count problem I created a fix in phpstan/phpstan-src#2041

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.10.x, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+3: Call to sprintf contains 1 placeholder, 0 values given.
Full report
Line Error
3 Call to sprintf contains 1 placeholder, 0 values given.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants