开发者

Deprecated function: require_once()

开发者 https://www.devze.com 2023-02-05 23:48 出处:网络
Recently, I started converting my Drupal 6 module on PHP 5.2.x to Drupal 7 on PHP 5.3.x, and now I get following warning

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

Deprecated function: Assigning the return va开发者_StackOverflow社区lue of new by reference is deprecated in require_once() (line 27 of C:\Users\ajinkya\Desktop\xampp\php\PEAR\SOAP\WSDL.php).

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

I am not able to figure out what is the cause of this warning. Has the behavior of require_once() changed in PHP 5.3.x?

file.inc in Drupal 7 has a line : require_once DRUPAL_ROOT . '/includes/stream_wrappers.inc; and it does not throw any warning. Why?

If I put error_reporting(E_ALL & ~E_DEPRECATED); in a setting.php of Drupal 7, the warning goes away. Is it good to suppress a warning like that?


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

&new was necessary in ancient PHP versions to ensure objects were always passed by reference. But in recent versions there is no reason to do this at all so it's deprecated.

I have no idea why your PHP reports an incorrect filename/line number though...


It is good to suppress an error like that?

Depends. Ignoring errors is never a good idea. Keeping strict reporting enabled is a good idea for the development stage. However, once PHP advises you with a debug message like that, you evaluate it and base an informed decision on that.

You can either work around the mentioned issue, fix it, or ignore it if it's not an actual problem.

Assigning an object by reference is unneeded and henceforth deprecated. It's however not a problem that will lead to errors, and it will never be semantically forbidden. Removing the syntax construct in future versions would break compatibility, so won't happen. The informed choice in this case is either to acknowledge and ignore the syntax hint, or remove the & since it's unneeded and its removal in this particular instance is mostly unlikely to break the behaviour.


I don't see anything on the PHP site indicating that require_once is deprecated. Perhaps something inside of HTTP/Request.php is deprecated instead? This is a pretty odd warning.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号