1.2.147. Clone Constant¶
Cloning constant is only possible since PHP 8.1. Until that version, constants could not be an object, and as such, could not be cloned.
This is also valid with default values, however they are assigned to a variable, which falls back to the classic clone usage.
Backward compatibility is OK, since PHP compile such code, and only checks at execution time that the constant is an object.
<?php
// new is available in constant definition, since PHP 8.2
const A = new B();
$c = clone A;
?>
See also New in initializers.
1.2.147.1. Specs¶
Short name |
Php/CloneConstant |
Rulesets |
All, Analyze, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, LintButWontExec |
Exakat since |
2.4.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
new, constant |
Note |
This issue may lint but will not run |
Available in |