1.2.229. Constant Scalar Expression¶
Since PHP 5.6, it is possible to use expression with Constants and default values. One may only use simple operators.
<?php
const THREE = 1 + 2;
const ARRAY = array(1,2,3);
// dynamic version
define('ARRAY', array(1,2,3));
// constant scalar expression are available for default values
function foo($a = 1 + M_PI) {
}
?>
See also New features..
1.2.229.1. Suggestions¶
Upgrade to PHP 7.0
Use a special value as the default value, and turn it into the actual value at constructor time
1.2.229.2. Specs¶
Short name |
Php/ConstantScalarExpression |
Rulesets |
All, Appinfo, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 5.6 and older |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Features |
constant-scalar-expression |
Available in |