Simple use this:
(object) array();
Since I started working with Zend framework I found myself in a situation when i needed empty object to be passed to or from some function. Instead of creating dummy class with __call function and storing values in some array, i think I’ve found nicer solution (see above).
So from now every time I need to fill some dummy object witch is not created, I create it on the fly by $o = (object) array(); and than I can fill it with variables, e.g: $o->variable = 'value';
What do you think ? Is there any better way to do it ?
No comments
Comments feed for this article
Trackback link
http://gondo.webdesigners.sk/php-create-new-empty-object/trackback/