tags:

views:

16

answers:

1

The following code causes a 'deprecated' error in PHP 5.3... Is there a substitute for it?

$this->widgets[$widget_class] = & new $widget_class();
+3  A: 

It'd be nice if you could specify what exactly the error message says, but I'm guessing it's informing you that object assignment by reference (=&) is deprecated. Objects are always assigned and passed by reference as of PHP 5, so including & is unnecessary. Simply drop the reference operator:

$this->widgets[$widget_class] = new $widget_class();
deceze
I don't think "assignment by reference" in general is deprecated but "new object" assignment is. See http://php.net/manual/en/migration53.deprecated.php - *"Assigning the return value of new by reference is now deprecated."*
Phil Brown
@Phil Good link, I was looking for a reference (no pun intended) in the manual, but couldn't find one.
deceze
@decez Same, had to use Google as I didn't think to look in the migrations section
Phil Brown