Hello;
I feel a bit bad posting just to ask a question when it’s been so long I haven’t helped anybody on these forums, but this is driving me crazy and I don’t know where to turn to. I’ve been googling for hours, reading the php manual, etc.
Ok look at this piece of code:
$xml = simplexml_load_file($dir."lib.php.xml");
$lang = "en";
$galleries = array();
$galleries[0]->name = &$xml->galleries->gallery[0]->$lang->name;
So I have these few variables, with $galleries->blah being a reference of $xml->galleries->blahblah; so far so good (The “$galleries[0]…” was initially "$galleries[$i], in a for loop but I removed for clarity).
Ok next part:
echo($xml->galleries->gallery[0]->$lang->name."<br/>");
$galleries[0]->name = "someName";
echo($galleries[0]->name."<br/>");
echo($xml->galleries->gallery[0]->$lang->name."<br/>");
I expect both values to be the same, but it outputs:
Earrings
someName
Earrings
What’s more puzzling, is if I switch the two lines:
echo($xml->galleries->gallery[0]->$lang->name."<br/>");
$xml->galleries->gallery[0]->$lang->name = "someName";
echo($galleries[0]->name."<br/>");
echo($xml->galleries->gallery[0]->$lang->name."<br/>");
it outputs:
Earrings
someName
someName
So, somehow, the value IS passed by reference…but in one way only. Why? Since I am passing the value by reference, why doesn’t both values change? As far as I read in the PHP documentation, both vars are supposed to be pointers to the same value!
I even read the bugs postings for like a million bugs without finding a reference to my problem.
Can anyone help? Or at least suggest something?
For all purposes, here is a snippet of my XML file, if it can give any clue (I doubt it, but maybe it’s a problem with simplexml):
<main>
......
<galleries>
<gallery id="0">
<items>
<item id="0" rank="0"/>
<item id="1" rank="1"/>
.....
</items>
<fr>
<name>Boucles D'Oreilles</name>
<description>Gallerie de Boucles D'Oreilles</description>
</fr>
<en>
<name>Earrings</name>
<description>Earrings Gallery</description>
</en>
</gallery>
</galleries>
</main>
And i even tried to replace the “$lang” variable with “fr” or “en”, it doesn’t change anything.
I’m stuck.