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();
0

1 Answer 1

4

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();
Sign up to request clarification or add additional context in comments.

3 Comments

I don't think "assignment by reference" in general is deprecated but "new object" assignment is. See php.net/manual/en/migration53.deprecated.php - "Assigning the return value of new by reference is now deprecated."
@Phil Good link, I was looking for a reference (no pun intended) in the manual, but couldn't find one.
Same, had to use Google as I didn't think to look in the migrations section

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.