$foo = (array)$foo; $foo['bar'] = '1234'; $foo = (object)$foo; 

Read more of this post