0

I'm looking at some old code that yields an error Strict Notice: Only variables should be assigned by reference on the code below on PHP 5.4.

$temp = &$xml->xpath(…);

Was the & ever needed in this operation in the earlier versions of PHP? xpath() already returns data according to current PHP documentation, so it would be assigned to $temp. I'm just not sure what it is or was trying to do by reference at the time it was written.

musicliftsme
  • 3,261
  • 9
  • 51
  • 95
  • OK, I understand what passing by reference is. I still don't see what passing by reference a function that returns a value does. `xpath()` returns an array of SimpleXMLElement objects. Is `$temp` supposed to be referencing that array somehow? I don't see how that would work. – musicliftsme Aug 13 '14 at 22:19
  • A leftover from outdated sources that tried to pass the return value of a function by reference, probably to avoid copying the value (which doesn't take place in current PHP, it's copy-on-write), or to properly pass a created object in PHP 4. – Sven Aug 13 '14 at 23:11
  • @Sven, Thanks for the response! So, I can remove `&` in PHP 5.3, correct? – musicliftsme Aug 14 '14 at 19:25

0 Answers0