src/Carbon/Carbon.php
public static function createSafe($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
    {
        $fields = array(
            'year' => array(0, 9999),
            'month' => array(0, 12),
            'day' => array(0, 31),
            'hour' => array(0, 24),
            'minute' => array(0, 59),
            'second' => array(0, 59),
        );

        foreach ($fields as $field => $range) {
            if ($$field !== null && (!is_int($$field) || $$field < $range[0] || $$field > $range[1])) {
                throw new InvalidDateException($field, $$field);
            }
        }

        $instance = static::create($year, $month, $day, $hour, $minute, $second, $tz);

        foreach (array_reverse($fields) as $field => $range) {
            if ($$field !== null && (!is_int($$field) || $$field !== $instance->$field)) {
                throw new InvalidDateException($field, $$field);
            }
        }

        return $instance;
    }
public static function createSafe($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
    {
        $fields = array(
            'year' => array(0, 9999),
            'month' => array(0, 12),
            'day' => array(0, 31),
            'hour' => array(0, 24),
            'minute' => array(0, 59),
            'second' => array(0, 59),
        );

        foreach ($fields as $field => $range) {
            if ($$field !== null && (!is_int($$field) || $$field < $range[0] || $$field > $range[1])) {
                throw new InvalidDateException($field, $$field);
            }
        }

        $instance = static::create($year, $month, $day, $hour, $minute, $second, $tz);

        foreach (array_reverse($fields) as $field => $range) {
            if ($$field !== null && (!is_int($$field) || $$field !== $instance->$field)) {
                throw new InvalidDateException($field, $$field);
            }
        }

        return $instance;
    }
public static function createSafe ( $ year = null , $ month = null , $ day = null , $ hour = null , $ minute = null , $ second = null , $ tz = null ) { $ fields = array ( 'year' => array ( 0 , 9999 ) , 'month' => array ( 0 , 12 ) , 'day' => array ( 0 , 31 ) , 'hour' => array ( 0 , 24 ) , 'minute' => array ( 0 , 59 ) , 'second' => array ( 0 , 59 ) , ) ; foreach ( $ fields as $ field => $ range ) { if ( $ $ field !== null && ( ! is_int ( $ $ field ) || $ $ field < $ range [ 0 ] || $ $ field > $ range [ 1 ] ) ) { throw new InvalidDateException ( $ field , $ $ field ) ; } } $ instance = static :: create ( $ year , $ month , $ day , $ hour , $ minute , $ second , $ tz ) ; foreach ( array_reverse ( $ fields ) as $ field => $ range ) { if ( $ $ field !== null && ( ! is_int ( $ $ field ) || $ $ field !== $ instance -> $ field ) ) { throw new InvalidDateException ( $ field , $ $ field ) ; } } return $ instance ; }
Create a new safe Carbon instance from a specific date and time.

If any of $year, $month or $day are set to null their now() values will
be used.

If $hour is null it will be set to its now() value and the default
values for $minute and $second will be their now() values.

If $hour is not null then the default values for $minute and $second
will be 0.

If one of the set values is not valid, an \InvalidArgumentException
will be thrown.

@param int|null                  $year
@param int|null                  $month
@param int|null                  $day
@param int|null                  $hour
@param int|null                  $minute
@param int|null                  $second
@param \DateTimeZone|string|null $tz

@throws \Carbon\Exceptions\InvalidDateException|\InvalidArgumentException

@return static
Create a new safe Carbon instance from a specific date and time .