1.2.780. New Initializers¶
Parameters, static variables and global constants may be initialized with an object.
This feature is available in PHP 8.1 and more recent. It is reported as an invalid constant expression in older PHP versions.
<?php
function foo( $a = new A) {
static $static = new B;
}
const A = new C;
?>
See also PHP RFC: New in initializers and `Nested Attributes`_.
1.2.780.1. Specs¶
Short name |
Php/NewInitializers |
Rulesets |
All, Appinfo, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80 |
Exakat since |
2.3.1 |
PHP Version |
With PHP 8.1 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
new-in-initializer, nested-attribute |
Available in |