Skip to content

Printf with precision format is not recognized #9677

@fmarchalemisys

Description

@fmarchalemisys

Bug report

This issue follows #9674.

As per the php doc regarding the precision in printf-like functions:

Note: If the period is specified without an explicit value for precision, 0 is assumed. If * is used, the precision is supplied as an additional integer value preceding the one formatted by the specifier.

If a * is used as the precision of a float number, phpstan complains about Call to printf contains 0 placeholders, 3 values given..

printf("%*.*f", 6, 2, 1);

PR #2543 fixed the variable width but issue #9674 failed to mention the variable precision.

Code snippet that reproduces the problem

https://phpstan.org/r/067797e9-18f6-4e48-874d-11f496dd6a1f

Expected output

Phpstan should detect the variable precision and accept one argument in addition to the width and the value to format.

Note that the width may be an actual digit:

printf("%6.*f", 2, 1);

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions