1.2.381. Double Object Assignation¶
The same object is assigned to two distinct variables. Given that objects are actually references to the same data, this is usually not necessary. Make sure that this is the intended purpose.
<?php
// $x and $y are the same object, as they both hold a reference to the same object.
// This means that changing $x, also changes $y.
$x = $y = new Z();
// $a and $b are distinct values, by default
$a = $b = 1;
?>
See also class.
1.2.381.1. Connex PHP features¶
1.2.381.1.1. Suggestions¶
Split the double assignation to two distinct instantiations.
Split the double assignation to two distinct lines.
1.2.381.1.2. Specs¶
Short name |
Structures/DoubleObjectAssignation |
Rulesets |
|
Exakat since |
2.1.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |