Assigning the return value of new by reference is deprecated

I recently upgraded to PHP 5.3.0 after having some issues with FASTCGI and 5.2.x on Windows but the moment I did this I started getting numerous warnings. The one that appeared the most was:

Assigning the return value of new by reference is deprecated

Apparently in PHP5 all objects are passed as reference and 5.3.0 formally deprecated the feature, which has forced me to turn off error reporting until I can update my code (including WordPress!).

So basically 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. So for instance, an overly simplified example would be:

class myClass{
    public $temp = array();

    function __construct(){
         $this->temp = array[1,2,3,4];
    }
}

$someArray = & new myClass();

The & sign tells PHP to return the value as a reference. In PHP 5.3.0 you don't need to specify the &.

It's a small change but it has HUGE impact!

Be Sociable, Share!
This entry was posted in PHP, Programming and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Denis

    Thank you!!! It works!!!

  • Ali

    Yes It works for me. Thanks
    The & sign tells PHP to return the value as a reference. In PHP 5.3.0 you don’t need to specify the &.

  • Nilesh.

    perfect ! :)
    u r a *

  • http://speakersforlaptopnews.com/ Alex

    It don’t work for my site. I delete all data in my site, reinstall but the errors still appear

  • thinkinglemur

    Hi Alex, you won’t have to delete all the data on your site, you will need to find the function(s) that uses the & to reference values and remove it from the code. The warning message will tell you the line of the code that contains the reference. If you want send across some more information I’ll attempt to help you fix this problem.