Menu
Error Identifier: print.nonString
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);
$values = [1, 2, 3];
print $values;
Why is it reported? #
The argument passed to print cannot be converted to a string. In the example above, $values is an array, which does not have a __toString() method and cannot be implicitly converted to a string.
How to fix it #
Convert the value to a string before printing:
<?php declare(strict_types = 1);
$values = [1, 2, 3];
-print $values;
+print implode(', ', $values);
How to ignore this error #
You can use the identifier print.nonString to ignore this error using a comment:
// @phpstan-ignore print.nonString
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: print.nonString
Rules that report this error #
- PHPStan\Rules\Cast\PrintRule [1]