1.2.379. 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.379.1. Suggestions

  • Split the double assignation to two distinct instantiations.

  • Split the double assignation to two distinct lines.

1.2.379.2. Specs

Short name

Structures/DoubleObjectAssignation

Rulesets

All, Analyze, Changed Behavior, Class Review

Exakat since

2.1.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

class

Available in

Entreprise Edition, Exakat Cloud