1.2.149. Clone Constant

Cloning constant is 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.149.2. Connex PHP features

1.2.149.2.1. Specs

Short name

Php/CloneConstant

Rulesets

All, Analyze, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, LintButWontExec

Exakat since

2.4.7

PHP Version

With PHP 8.1 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud