Error Identifier: cast.deprecated
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);
$value = (integer) '42';
$flag = (boolean) 1;
$rate = (double) '3.14';
Why is it reported? #
PHP 8.5 deprecates non-standard cast syntax variants. The casts (integer), (boolean), (double), and (binary) are aliases for (int), (bool), (float), and (string) respectively. While they have worked historically, they are now deprecated and will be removed in a future PHP version.
How to fix it #
Replace the deprecated cast syntax with the standard form:
<?php declare(strict_types = 1);
-$value = (integer) '42';
-$flag = (boolean) 1;
-$rate = (double) '3.14';
+$value = (int) '42';
+$flag = (bool) 1;
+$rate = (float) '3.14';
How to ignore this error #
You can use the identifier cast.deprecated to ignore this error using a comment:
// @phpstan-ignore cast.deprecated
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: cast.deprecated