4

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 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 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?

hakre
  • 193,403
  • 52
  • 435
  • 836
Ajinkya Kulkarni
  • 984
  • 2
  • 11
  • 19
  • In my experience, an error is telling you something is wrong. It is never good to suppress errors. That being said, I don't know what is wrong here. – aqua Jan 22 '11 at 20:32
  • In this case, I think you're only suppressing warnings, not errors. – jocull Jan 22 '11 at 20:35

3 Answers3

5

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...

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • That's the ticket. The error is reported at the `require_once` call since it's a parse-time error (but it still should be better)... – ircmaxell Jan 22 '11 at 20:35
  • There were many instances (around 100) of '&new' in php files under PEAR folder. I replaced them all with 'new'. Before I used to get three same warning messages, but now just one. I was kind of skeptical in replacing all instances of '&new' with 'new' though. Also, I thought if I use the latest version of PEAR for PHP 5.3, there won't be any sort of problem like this. – Ajinkya Kulkarni Jan 26 '11 at 20:57
2

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.

mario
  • 144,265
  • 20
  • 237
  • 291
0

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.

jocull
  • 20,008
  • 22
  • 105
  • 149