Error Identifier: argument.sscanf
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
sscanf('42 hello', '%d%d', $number);
Why is it reported? #
The format string passed to sscanf() contains placeholders that expect a corresponding variable argument for each one. When sscanf() is called with additional arguments beyond the format string, each % placeholder must have a matching variable to store the scanned value. A mismatch between the number of placeholders and the number of provided variables means some values will not be captured.
How to fix it #
Pass the correct number of variable arguments to match the format string placeholders:
<?php declare(strict_types = 1);
-sscanf('42 hello', '%d%d', $number);
+sscanf('42 hello', '%d%d', $number, $other);
Or adjust the format string to match the number of arguments:
<?php declare(strict_types = 1);
-sscanf('42 hello', '%d%d', $number);
+sscanf('42 hello', '%d', $number);
How to ignore this error #
You can use the identifier argument.sscanf to ignore this error using a comment:
// @phpstan-ignore argument.sscanf
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: argument.sscanf