比laravel函数optional更简洁的写法
optional
函数接受任何参数,并允许你访问该对象上的属性或调用其方法。如果给定对象为 null
,属性或方法将返回 null
而不是引发错误:Attempt to read property "street" on null
return optional($user->address)->street;
而更简洁的写法:
return $user->address?->street;
高认可度评论:
PHP8 新增的语法糖
PHP8 新增的语法糖
这用7.2的虽然也是laralvel,享受不到这个服务
像极了 JavaScript