Error Identifier: function.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.
This error is reported by phpstan/phpstan-deprecation-rules.
Code example #
<?php declare(strict_types = 1);
/**
* @deprecated Use newHelper() instead.
*/
function oldHelper(): void
{
}
oldHelper();
Why is it reported? #
The code calls a function that has been marked as deprecated via a @deprecated PHPDoc tag, or it calls a function like ini_get() or ini_set() with a deprecated INI option. Deprecated functions and options are planned for removal in a future PHP version and should no longer be used.
How to fix it #
Replace the call with the recommended alternative:
<?php declare(strict_types = 1);
-oldHelper();
+newHelper();
For deprecated INI options, use the replacement option or remove the call:
<?php declare(strict_types = 1);
-ini_set('assert.quiet_eval', '0');
+// assert.quiet_eval was removed in PHP 8.0
How to ignore this error #
You can use the identifier function.deprecated to ignore this error using a comment:
// @phpstan-ignore function.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: function.deprecated