PHP 5.4: disable warning "Creating default object from empty value"

Posted by Werner on Stack Overflow See other posts from Stack Overflow or by Werner
Published on 2012-11-10T16:53:47Z Indexed on 2012/11/10 16:59 UTC
Read the original article Hit count: 256

Filed under:
|
|

I want to migrate code from PHP 5.2 to 5.4. This worked fine so far except that all the code I use makes extensive use of just using an object with a member without any initialisation, like:

$MyObject->MyMember = "Hello";

which results in the warning: "Creating default object from empty value"

I know that the solution would be to use:

$MyObject = new stdClass();
$MyObject->MyMember = "Hello";

but it would be A LOT OF WORK to change this in all my code, because I use this many times in different projects. I know, it's not good style, but unfortunately I'm not able to spend the next weeks adding this to all of my code.

I know I could set the php error_reporting to not reporting warnings, but I want to be able to still get other warnings and notices. This warning doesn't seem to be effected by enable or disable E_STRICT at all. So is there a way to just disable this warning?!

© Stack Overflow or respective owner

Related posts about php

Related posts about error-reporting