Re: merging objects
| From: | Jason k Larson | Date: | Tue, 08 Apr 2003 11:55:17 +0000 |
| Subject: | Re: merging objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142840@lists.php.net to get a copy of this message | ||
Actually, you don't need to type cast it, foreach operates on a copy of the variable anyway, but it is perfectly capable of looping through objects.
Something like this should work but will overwrite existing index/values
foreach ($object2 as $index => $value)
{
//value passed by reference to the index
$object1->{$index} =& $object2->{$index};
}
HTH,
Jason k Larson
Ernest E Vogelsinger wrote:
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.