Deprecated Function: require_once ()

I recently started converting my Drupal 6 module to PHP 5.2.x into Drupal 7 to PHP 5.3.x, and now I get the following warning

Deprecated function: assignment The return value of new by reference is deprecated in require_once() (line 27 of C:. \ Users \ ajinkya \ Desktop \ XAMPP \ PHP \ PEAR \ SOAP \ WSDL.php)

Line 27 WSDL.php: require_once 'HTTP/Request.php';

I can not understand what is the reason for this warning. Is require_once() behavior require_once() in PHP 5.3.x?

file.inc in Drupal 7 has the line: require_once DRUPAL_ROOT . '/includes/stream_wrappers.inc; require_once DRUPAL_ROOT . '/includes/stream_wrappers.inc; and does not cause any warnings. Why?

If I put error_reporting(E_ALL & ~E_DEPRECATED); in the settings.php file of Drupal 7, the warning disappears. Is it good to suppress such a warning?

+4
source share
3 answers

The error message says the code uses $something = &new SomeObject(); instead of $something = new SomeObject(); .

&new was needed in ancient versions of PHP to ensure that objects were always passed by reference. But in the latest versions there is no reason to do this at all, so it is outdated.

I don't know why your PHP reports the wrong file name / line number, though ...

+5
source

Are you good at suppressing such an error?

It depends. Ignoring mistakes is never a good idea. Maintaining rigorous reporting is a good idea for the development phase. However, as soon as PHP informs you of this debugging message, you will evaluate it and substantiate the decision made.

You can either get around the problem mentioned, or fix it, or ignore it if it is not a problem.

Assigning an object by reference is not required and is now deprecated. However, this is not a problem that will lead to errors, and it will never be semantically prohibited. Removing syntax constructs in future versions will result in a compatibility violation, so this will not happen. In this case, a conscious choice is to confirm or ignore the syntax hint or remove & , since it is not needed, and deleting it in this particular instance is unlikely to violate the behavior.

+2
source

I don’t see anything on the PHP site, indicating that require_once is deprecated. Perhaps something inside HTTP/Request.php instead? This is a rather strange warning.

0
source

Source: https://habr.com/ru/post/1336625/


All Articles