If your objects only contain fields (no methods), this works:
$obj_merged = (object) array_merge((array) $obj1, (array) $obj2);
This actually also works when objects have methods. (tested with PHP 5.3 and 5.6)
More Related Contents:
- PHP OOP core framework
- mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object
- Creating anonymous objects in php
- remove duplicate key array from php [duplicate]
- PHP method chaining or fluent interface?
- Modify array values in foreach loop
- What is the point of interfaces in PHP?
- PHP: Storing ‘objects’ inside the $_SESSION
- Best practice on PHP singleton classes [duplicate]
- Multiple Inheritance in PHP
- When should I declare variables in a PHP class?
- If Singletons are bad then why is a Service Container good?
- When should I use stdClass and when should I use an array in php oo code?
- How to use class methods as callbacks
- Chaining Static Methods in PHP?
- Dynamically create PHP object based on string
- Syntax error while defining an array as a property of a class
- Nested or Inner Class in PHP
- How do you pass objects by reference in PHP 5?
- what is Object Cloning in php?
- Unresolvable dependency resolving [Parameter #0 [ $name ]]
- dynamic class names in php
- Call parent constructor before child constructor in PHP
- PHP’s function to list all objects’s properties and methods
- Passing variable from controller to view in CodeIgniter
- How to decode a JSON String with several objects in PHP?
- Is Multiple Inheritance allowed at class level in PHP?
- Access object property with disallowed character in property name
- Method Chains PHP OOP
- PHP – Implement logging mechanism to file in several classes