PHP 5.4 creating object and arrays on the fly? 31 May 2012

Hi All,

As of PHP 5.4 you will get error message for using a variable as a array or object without declaring it as a an array or object.

For example, PHP 5.3

// This would work
$foo = null;
$foo->bar = "foo bar";

For example, PHP 5.4

// You need to do this
$foo = new stdClass();
$foo->bar = "foo bar";

The way I see it PHP 5.4 has it right. And by giving you a error for this bad bit of coding practice it will make the world of PHP more readable and more friendly.

Laters, Happy Coding