PHP array item modfied unexplainingly (to me)

Hi all

Here is a piece of PHP code making substitutions in elements of an array $this->_equations :

for ($i = ($currentEquationRank + 1); $i < $nbrEquations; $i++) {
    logError("i", $i);
    logError("this->_equations[0] avant substitution", $this->_equations[0]->displayEquation());
    $this->_equations[$i]->substitutionInTerms( 
        $this->_equations[$currentEquationRank]->getType1(),
        $this->_equations[$currentEquationRank]->getType2()
    );
    logError("this->_equations[0] après substitution", $this->_equations[0]->displayEquation());
}

When i=18, my log reports:

this->_equations[0] avant substitution
{"boundVar":0} = {"baseType":"P"}
this->_equations[0] après substitution
{"baseType":"P"} = {"baseType":"P"}

I don’t understand why this->_equations[0] would change while we are acting on another element of the array.

Here is below the code of the functions getType1 and getType2 ($this->_type1 and $this->_type2 are arrays supposed to be cloned in $res):

public function getType1()
{
    $res = $this->_type1;
    return $res;
}

public function getType2()
{
    $res = $this->_type2;
    return $res;
}

Would someone have hints to make me understand please ?

There’s probably an expression somewhere that’s assigning a value, using one =, vs comparing a value, using two ==.

It would require having all the code and some sample data, i.e. a running example, to be able to specifically help.

Sponsor our Newsletter | Privacy Policy | Terms of Service