deprecated: Assigning return value of new by reference
Problem:
Assigning objects using the new keyword by reference, as shown below, produces a deprecation warning in PHP5:
<code class="php">$obj_md = new MDB2();</code>
Answer:
In PHP5, the use of & (ampersand) when assigning the return value of new is deprecated. The warning can be resolved by removing the & from the code.
<code class="php">$obj_md = new MDB2(); // No ampersand</code>
Note that the assignment of objects by reference was a common idiom in PHP4, but it is no longer necessary in PHP5. For more information on this deprecation, please refer to the [PHP documentation](https://www.php.net/manual/en/migration5.deprecated.php).
The above is the detailed content of Is Assigning New Objects by Reference Deprecated in PHP5?. For more information, please follow other related articles on the PHP Chinese website!