12

I've noticed in the Joomla documentation, such as for JFactory/getSession, that the examples use assign-by-reference (=&), rather than a simple assignment (=).

$session =& JFactory::getSession();

Is this just out-of-date, or purposefully covering users of PHP 4?

Is this necessary under PHP 5? Or is there something Joomla related that I've overlooked?

2
  • Great question! I've often wondered if I should be using the equals symbol and ampersand or just the equals symbol.
    – TryHarder
    Apr 28, 2014 at 11:15
  • Some docs are not updated. When you spot something, just hit the edit button, it's a wiki. Apr 28, 2014 at 13:23

1 Answer 1

9

This was used for PHP4 times. From PHP5 onwards objects are assigned by reference, so there is no need to do that explicitly.

3
  • 1
    in php 5 it causes many strict standards warnings to have it as well, and there is a lot of it in the Joomla core, sometimes causing fun times when you swap to development error reporting. Another one of those changes in PHP that makes backwards compatibility hard. Apr 28, 2014 at 12:52
  • It's bad in Joomla 1.5 since it was written to support PHP 4.3 up. With 2.5 and 3.x, the amount of E_STRICT errors in core is minimal if any.
    – Michael
    Apr 29, 2014 at 0:25
  • 1
    Thanks, I had a assumed it must have been a PHP4 hangover, but with Joomla 1.6+ requiring PHP5+ I was beginning to wonder. Minor point, but objects are not actually "assigned by reference" in PHP5. The assign-by-reference operator is not reqd (in most cases) because class instances are stored differently in PHP5. (Class instances hold an "object identifier" rather than the value itself, as in PHP4.) An "object identifier" is assigned in PHP5, rather than the object value. The net result is similar, but there are differences.
    – MrWhite
    Apr 29, 2014 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.