0

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;
NullUserException
  • 83,810
  • 28
  • 209
  • 234
user1781038
  • 111
  • 3
  • 10
  • 1
    Possible duplicates: http://stackoverflow.com/questions/1949966/php-strict-standards-creating-default-object-from-empty-value-how-to-fix and http://stackoverflow.com/questions/1243749/php5-creating-default-object-from-empty-value – enenen Oct 28 '12 at 16:22
  • You cant do what your doing, unless you initialize `$searchresult[$pluginname][$i]` as a stdClass() first or create a special __set() method in the class. – Lawrence Cherone Oct 28 '12 at 16:24

2 Answers2

1

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);
theredled
  • 998
  • 9
  • 20
  • thanks now warnings removed.. i use $searchresult[$pluginname][$i]=new stdClass();.... also Lawrence Cherone suggests... thanks everybody for your kind help.. Regards – user1781038 Oct 29 '12 at 12:19
0

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.

Roberto
  • 1,944
  • 1
  • 30
  • 42