. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Core\Utils; use stdClass; class ObjectUtil { /** * Deep clone. */ public static function clone(stdClass $source): stdClass { $cloned = (object) []; foreach (get_object_vars($source) as $k => $v) { $cloned->$k = self::cloneItem($v); } return $cloned; } /** * @param mixed $item * @return mixed */ private static function cloneItem($item) { if (is_array($item)) { $cloned = []; foreach ($item as $i => $v) { $cloned[$i] = self::cloneItem($v); } return $cloned; } if ($item instanceof stdClass) { return self::clone($item); } if (is_object($item)) { return clone $item; } return $item; } }