user1781038
user1781038

Reputation: 111

after upgrading my php5.4 Creating default object from empty value

I have a problem related to php version 5.4. I am using php5.4. Before it was 5.2.

Now I have problem after upgrading. Now my site has lots of warnings

Creating default object from empty value

I am trying to solve this by checking other posts, but no success.

Warnings are at this line

$searchresult[$pluginname][$i]->title = $value->title;

Upvotes: 0

Views: 985

Answers (2)

Roberto
Roberto

Reputation: 1944

This is the stupid way to approach this problem, but you get that warning off you back by setting error_reporting to E_ALL & ~E_NOTICE & ~E_STRICT.

It's specially helpful if you're going to do the wrong thing any way and not rewrite the code as @theredled suggests above.

Upvotes: 0

theredled
theredled

Reputation: 1040

Yes, with older versions of PHP, you could do :

$a = null;
$a->somevar = 3;`

Because $a was automaticly turned into stdClass type.

With PHP 5.4 you can't do that : you have to instanciate $a manually.

$a = new stdClass(); 
$a->somevar = 3;`

Or better, use arrays if you can :

$a = array('somevar' => 3);

Upvotes: 1

Related Questions