Is Assigning New Objects by Reference Deprecated in PHP5?

Barbara Streisand
Release: 2024-10-23 21:30:30
Original
199 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!