PHP Error: Creating default object from empty value

PHP 5 introduces the E_STRICT error reporting constant. The PHP manual states "Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.". Thus it's recommendable to enable strict PHP errors.

About strict mode (E_STRICT)

Enabling the strict mode is done via the INI file (php.ini) or via code during runtime:

  ini_set('error_reporting', E_ALL | E_STRICT);

The above code sets error_reporting to E_ALL and E_STRICT, because E_STRICT is not part of the E_ALL constant.

Disabling the strict mode works vice versa:

  ini_set('error_reporting', E_ALL);

"Creating default object from empty value"

This error tells you your code instantiated a default object (of type stdClass) implicitely. The referenced part of your code most likely looks like

  $object->foo = 'bar';

PHP is strict and doesn't accept this, because you didn't create the $object explicitely! The solution to this is rather simple: add the explicit instantiation and you're done! The code should look like:

  $object = new stdClass(); // instantiate $object explicitely
  $object->foo = 'bar'; // now it's save to do this!

YAY! Thanks for this, you are

YAY! Thanks for this, you are a legend :)

I was getting an error in Bumble-Bee v1.15:

"Strict Standards: Creating default object from empty value in /path/to/folder/bumble-bee/system-inc/php-gettext/gettext.inc on line 152"

Fixed by adding at line 152:

$text_domains[$domain] = new stdClass();

Woohooo!

Thanks! This post helps me.

Thanks! This post helps me.

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is to verify you're a human visitor with at least everage IQ. Please do not use a calculator.
3 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.