Error Identifier: function.inVoidCast
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);
function doFoo(): string
{
return 'hello';
}
(void) doFoo();
Why is it reported? #
A function call is wrapped in a (void) cast, but the function does not require its return value to be used. The (void) cast is a way to explicitly acknowledge that a return value is being discarded, but it is only necessary for functions marked with #[\NoDiscard]. For other functions, the cast is redundant.
How to fix it #
Remove the unnecessary (void) cast:
<?php declare(strict_types = 1);
-(void) doFoo();
+doFoo();
How to ignore this error #
You can use the identifier function.inVoidCast to ignore this error using a comment:
// @phpstan-ignore function.inVoidCast
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.inVoidCast
Rules that report this error #
- PHPStan\Rules\Functions\CallToFunctionStatementWithNoDiscardRule [1]