Re: merging objects

From: Date: Tue, 08 Apr 2003 14:13:39 +0000
Subject: Re: merging objects
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-142868@lists.php.net to get a copy of this message
what does cast an object as an array mean? "Ernest E Vogelsinger" <ernest@vogelsinger.at> wrote in message news:5.1.1.6.2.20030408114600.02bf0488@mail.vogelsinger.at... > At 11:44 08.04.2003, Diana Castillo said: > --------------------[snip]-------------------- > >is there any way to add one object to the end of another ? (they are the > >same type of objects) > --------------------[snip]-------------------- > > What do you really want to achieve? If the objects are "of the same type", > attributes of one would overwrite existing attributes of the other object. > > You may cast an object as an array. As such you may loop through it as here: > > foreach ((array)$obj1 as $key => $value) > $obj2->$key = $value; > > This would "merge" the objects, overwriting existing attributes in $obj2 > with the values of $obj1. > > > -- > >O Ernest E. Vogelsinger > (\) ICQ #13394035 > ^ http://www.vogelsinger.at/ > >

« previous php.general (#142868) next »