PHP

Anonymous Objects in PHP

For real quick and dirty one-liner anonymous objects, just cast an associative array:

<?php
$obj
= (object) array('foo' => 'bar', 'property' => 'value');

echo
$obj->foo; // prints 'bar'
echo $obj->property; // prints 'value'
?>

... no need to create a new class or function to accomplish it.

Source: http://www.php.net/manual/en/language.oop5.php#84292

#
Syndicate content