Home  >  Article  >  Backend Development  >  Is Assigning New Objects by Reference Deprecated in PHP5?

Is Assigning New Objects by Reference Deprecated in PHP5?

Barbara Streisand
Barbara StreisandOriginal
2024-10-23 21:30:30200browse

Is Assigning New Objects by Reference Deprecated in PHP5?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn