1.2.345. Deprecated Callable¶
Callable functions that are supported by call_user_func($callable)
, but not with the $callable()
syntax are deprecated.
One important aspect is the loss of context : ‘self::method’ may be created anywhere in the code, while self::class can only be used inside a class, and, in that case, inside the target class. It is recommended to update the code with any PHP version, to prepare for the future removal of the feature.
<?php
class x {
// This will fail
function foo(callable $callable) {
$callable();
}
function method() {
}
}
$x = new x;
$x->foo('self::method');
?>
See also PHP RFC: Deprecate partially supported callables.
1.2.345.2. Connex PHP features¶
1.2.345.2.1. Suggestions¶
Replace the keyword (such as self) by the full class name, with self::class.
Use a variable and the $s(…) syntax.
1.2.345.2.2. Specs¶
Short name |
Functions/DeprecatedCallable |
Rulesets |
|
Exakat since |
2.3.1 |
PHP Version |
With PHP 8.2 and older |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Note |
This issue may lint but will not run |
Available in |