PHP 7.2 中 count 更加严格了
先贴代码
在PHP7.2中,如果参数不是数组,或者没有实现 Countable 接口,就会报错了。
在这个rfc中有提到,https://wiki.php.net/rfc/counting_non_coun...
所以用到 count 的地方,需要注意一下了
比如下面这段代码
$user = User::find(1);
if (count($user)) {
do something
}
其实可以这样,
$user = User::find(1);
if ($user) {
do something
}
推荐文章: