PHP: Assigning return value by reference is deprecated

phpRecently I upgraded to PHP 5.3.2 on my testing server. But soon I got some warning message from some Joomla‘s new themes like JV Eoty. It worked well in PHP 5.2.x, but the moment I did this I started getting numerous warnings. The one that appeared the most was:

Deprecated: Assigning the return value of new by reference is deprecated in jv_eoty/jv_menus/jv.common.php on line 61

Apparently in PHP5 all objects are passed as reference and 5.3.x formally deprecated the feature, which has forced me to turn off error reporting until I can update all my php code.

So the problem is that traditionally objects would be passed by value and you had to explicitly declare when you wanted the object to be passed by reference, but in PHP 5.3.x you don’t need to do that any more.  For instance, a simplified example would be:

class myClass{
  public $temp = array();
  function new_construct() {
    $this->temp = array[1,2,3];
  }
}

$someArray = & new myClass();

The & sign tells PHP to return the value as a reference. In PHP 5.3.x you don’t need to specify the &, otherwise, you’ll get to warning message that we mentioned here!

Leave a comment

Your email address will not be published. Required fields are marked *