1.2.151. Clone With Non-Object¶
The
clonekeyword must be used on variables, properties or results from a function or method call.
clone cannot be used with constants or literals.
Cloning a non-object lint but won’t execute.
<?php
class x { }
$x = new x();
// Valid clone
$y = clone $x;
// Invalid clone
$y = clone x;
?>
See also Object cloning.
1.2.151.2. Connex PHP features¶
1.2.151.2.1. Suggestions¶
Only clone containers (like variables, properties…)
Add typehint to injected properties, so they are checked as objects.
1.2.151.2.2. Specs¶
Short name |
Classes/CloneWithNonObject |
Rulesets |
|
Exakat since |
1.7.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Note |
This issue may lint but will not run |
Available in |