1.2.158. Closure In Constant¶
Closures may be used as constant value, since PHP 8.5. The closure <https://www.php.net/`closure>`_ has to be static, and not collect any variable from the context.
It may be a global or a class constant. Later, it is used
<?php
const A = static function() {};
class X {
const B = static function ($b) {echo __METHOD__;};
}
(X::B)(1);
?>
1.2.158.1. Connex PHP features¶
1.2.158.1.1. Specs¶
Short name |
Php/ClosureInConstant |
Rulesets |
All, Appinfo, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, CompatibilityPHP81, CompatibilityPHP82, CompatibilityPHP83, CompatibilityPHP84 |
Exakat since |
2.7.0 |
PHP Version |
With PHP 8.5 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |