public static function defaults($object, $defaults)
    {
        $defaults = array_slice(func_get_args(), 1);

        if ($object instanceof \stdClass) {
            $object = (array)$object;
            $castDown = true;
        }

        $result = $object;
        $isArray = is_array($object);
        static::each($defaults, function ($default) use (& $result, $isArray) {
            if (!static::isTraversable($default))
                throw new \InvalidArgumentException("cannot use " . static::typeOf($default) . " as default");

            if ($isArray)
                return $result += static::toArray($default);

            static::each($default, function ($item, $index) use (& $result) {
                if (!static::has($result, $index))
                    static::set($result, $index, $item);
            });
        });

        return !empty($castDown) ? (object)$result : $result;
    }
public static function defaults($object, $defaults)
    {
        $defaults = array_slice(func_get_args(), 1);

        if ($object instanceof \stdClass) {
            $object = (array)$object;
            $castDown = true;
        }

        $result = $object;
        $isArray = is_array($object);
        static::each($defaults, function ($default) use (& $result, $isArray) {
            if (!static::isTraversable($default))
                throw new \InvalidArgumentException("cannot use " . static::typeOf($default) . " as default");

            if ($isArray)
                return $result += static::toArray($default);

            static::each($default, function ($item, $index) use (& $result) {
                if (!static::has($result, $index))
                    static::set($result, $index, $item);
            });
        });

        return !empty($castDown) ? (object)$result : $result;
    }
public static function defaults ( $ object , $ defaults ) { $ defaults = array_slice ( func_get_args ( ) , 1 ) ; if ( $ object instanceof \ stdClass ) { $ object = ( array ) $ object ; $ castDown = true ; } $ result = $ object ; $ isArray = is_array ( $ object ) ; static :: each ( $ defaults , function ( $ default ) use ( & $ result , $ isArray ) { if ( ! static :: isTraversable ( $ default ) ) throw new \ InvalidArgumentException ( "cannot use " . static :: typeOf ( $ default ) . " as default" ) ; if ( $ isArray ) return $ result += static :: toArray ( $ default ) ; static :: each ( $ default , function ( $ item , $ index ) use ( & $ result ) { if ( ! static :: has ( $ result , $ index ) ) static :: set ( $ result , $ index , $ item ) ; } ) ; } ) ; return ! empty ( $ castDown ) ? ( object ) $ result : $ result ; }
Fill in null properties in object with values from the defaults objects, and return the object. As soon as the
property is filled, further defaults will have no effect.

@category Object Functions

@param traversable $object the object to fill
@param traversable $defaults multiple, the objects or array that will fill object's missing keys

@throws InvalidArgumentException if one of the $defaults object is not traversable

@return object
Fill in null properties in object with values from the defaults objects and return the object . As soon as the property is filled further defaults will have no effect .