Menu

← Back to function.*

Error Identifier: function.uselessReturnValue

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

$output = print_r(['name' => 'John', 'age' => 30]);

Why is it reported? #

The return value of a function like print_r(), var_export(), or highlight_string() is being used, but without passing true as the second parameter, these functions print their output directly and return a useless value (true for print_r(), null for var_export()).

In the example above, print_r() is called without the $return parameter set to true, so it prints the array directly to the output and returns true. Assigning or using this return value is meaningless.

How to fix it #

Pass true as the second parameter to return the output as a string instead of printing it:

 <?php declare(strict_types = 1);
 
-$output = print_r(['name' => 'John', 'age' => 30]);
+$output = print_r(['name' => 'John', 'age' => 30], true);

Or if the intent is only to print the value, do not use the return value:

 <?php declare(strict_types = 1);
 
-$output = print_r(['name' => 'John', 'age' => 30]);
+print_r(['name' => 'John', 'age' => 30]);

How to ignore this error #

You can use the identifier function.uselessReturnValue to ignore this error using a comment:

// @phpstan-ignore function.uselessReturnValue
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: function.uselessReturnValue

Rules that report this error #

  • PHPStan\Rules\Functions\UselessFunctionReturnValueRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.