两个 Carbon 变量用 `>` 比较大小
两个 Carbon 变量比较大小,直接用 > 号比较会有什么问题吗?:
我测试没有发现问题
那么>
比较和 $startTime->gt($endTime)
有什么区别呢?
if ($startTime > $endTime) {
throw new Exception ();
}
找到了 官方文档
Those methods use natural comparisons offered by PHP $date1 == $date2 so all of them will ignore milli/micro-seconds before PHP 7.1, then take them into account starting with 7.1.
Datetime 类型的对象是可以用
>
<
直接比较的,Carbon 继承了 Datetime 所以也是没问题的,官方文档