I would like to be able to do the following:
$obj = new stdClass;
$obj->status = \"success\";
$obj2 = new stdClass;
$obj2->message = \"OK\";
You could use get_object_vars() on one of the stdClass
object, iterate through those, and add them to the other:
function extend($obj, $obj2) {
$vars = get_object_vars($obj2);
foreach ($vars as $var => $value) {
$obj->$var = $value;
}
return $obj;
}
Not sure if you'd deem that more elegant, mind you.
Edit: If you're not stingy about actually storing them in the same place, take a look at this answer to a very similar question.