public static function fromComponents(
        int $years = null,
        int $months = null,
        int $weeks = null,
        int $days = null,
        int $hours = null,
        int $minutes = null,
        int $seconds = null,
        int $microseconds = null
    ) : self {
        if (!($years || $months || $weeks || $days || $hours || $minutes || $seconds || $microseconds)) {
            throw new \InvalidArgumentException('At least one component is required.');
        }
        
        $years        = $years ?: 0;
        $months       = $months ?: 0;
        $weeks        = $weeks ?: 0;
        $days         = $days ?: 0;
        $hours        = $hours ?: 0;
        $minutes      = $minutes ?: 0;
        $seconds      = $seconds ?: 0;
        $microseconds = $microseconds ?: 0;
        
        $specification = 'P';
        
        if ($years) {
            $specification .= $years . 'Y';
        }
        
        if ($months) {
            $specification .= $months . 'M';
        }
        
        if ($weeks) {
            $specification .= $weeks . 'W';
        }
        
        if ($days) {
            $specification .= $days . 'D';
        }
        
        if ($hours || $minutes || $seconds) {
            $specification .= 'T';
            
            if ($hours) {
                $specification .= $hours . 'H';
            }
            
            if ($minutes) {
                $specification .= $minutes . 'M';
            }
            
            if ($seconds) {
                $specification .= $seconds . 'M';
            }
        }
        
        return new static(new \DateInterval($specification), $microseconds);
    }
public static function fromComponents(
        int $years = null,
        int $months = null,
        int $weeks = null,
        int $days = null,
        int $hours = null,
        int $minutes = null,
        int $seconds = null,
        int $microseconds = null
    ) : self {
        if (!($years || $months || $weeks || $days || $hours || $minutes || $seconds || $microseconds)) {
            throw new \InvalidArgumentException('At least one component is required.');
        }
        
        $years        = $years ?: 0;
        $months       = $months ?: 0;
        $weeks        = $weeks ?: 0;
        $days         = $days ?: 0;
        $hours        = $hours ?: 0;
        $minutes      = $minutes ?: 0;
        $seconds      = $seconds ?: 0;
        $microseconds = $microseconds ?: 0;
        
        $specification = 'P';
        
        if ($years) {
            $specification .= $years . 'Y';
        }
        
        if ($months) {
            $specification .= $months . 'M';
        }
        
        if ($weeks) {
            $specification .= $weeks . 'W';
        }
        
        if ($days) {
            $specification .= $days . 'D';
        }
        
        if ($hours || $minutes || $seconds) {
            $specification .= 'T';
            
            if ($hours) {
                $specification .= $hours . 'H';
            }
            
            if ($minutes) {
                $specification .= $minutes . 'M';
            }
            
            if ($seconds) {
                $specification .= $seconds . 'M';
            }
        }
        
        return new static(new \DateInterval($specification), $microseconds);
    }
public static function fromComponents ( int $ years = null , int $ months = null , int $ weeks = null , int $ days = null , int $ hours = null , int $ minutes = null , int $ seconds = null , int $ microseconds = null ) : self { if ( ! ( $ years || $ months || $ weeks || $ days || $ hours || $ minutes || $ seconds || $ microseconds ) ) { throw new \ InvalidArgumentException ( 'At least one component is required.' ) ; } $ years = $ years ? : 0 ; $ months = $ months ? : 0 ; $ weeks = $ weeks ? : 0 ; $ days = $ days ? : 0 ; $ hours = $ hours ? : 0 ; $ minutes = $ minutes ? : 0 ; $ seconds = $ seconds ? : 0 ; $ microseconds = $ microseconds ? : 0 ; $ specification = 'P' ; if ( $ years ) { $ specification .= $ years . 'Y' ; } if ( $ months ) { $ specification .= $ months . 'M' ; } if ( $ weeks ) { $ specification .= $ weeks . 'W' ; } if ( $ days ) { $ specification .= $ days . 'D' ; } if ( $ hours || $ minutes || $ seconds ) { $ specification .= 'T' ; if ( $ hours ) { $ specification .= $ hours . 'H' ; } if ( $ minutes ) { $ specification .= $ minutes . 'M' ; } if ( $ seconds ) { $ specification .= $ seconds . 'M' ; } } return new static ( new \ DateInterval ( $ specification ) , $ microseconds ) ; }
Note that if weeks and days are both specified, only days will be used and weeks will be ignored.

@param int|null $years
@param int|null $months
@param int|null $weeks
@param int|null $days
@param int|null $hours
@param int|null $minutes
@param int|null $seconds
@param int|null $microseconds

@return self
Note that if weeks and days are both specified only days will be used and weeks will be ignored .