Menu

← Back to argument.*

Error Identifier: argument.fscanf

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);

/** @var resource $handle */
$handle = fopen('data.txt', 'r');

fscanf($handle, '%d%d', $number);

Why is it reported? #

The format string passed to fscanf() contains placeholders that expect a corresponding variable argument for each one. When fscanf() 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);
 
 /** @var resource $handle */
 $handle = fopen('data.txt', 'r');

-fscanf($handle, '%d%d', $number);
+fscanf($handle, '%d%d', $number, $other);

Or adjust the format string to match the number of arguments:

 <?php declare(strict_types = 1);
 
 /** @var resource $handle */
 $handle = fopen('data.txt', 'r');

-fscanf($handle, '%d%d', $number);
+fscanf($handle, '%d', $number);

How to ignore this error #

You can use the identifier argument.fscanf to ignore this error using a comment:

// @phpstan-ignore argument.fscanf
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.fscanf

Rules that report this error #

  • PHPStan\Rules\Functions\PrintfParametersRule [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.