- echo count('123123');
- list(,$v) = each($_GET);
报错信息如下:
- Warning: count(): Parameter must be an array or an object that implements Countable in D:\Qampp\htdocs\adminer\compile.php on line 3
- Deprecated: The each() function is deprecated. This message will be suppressed on further calls in D:\Qampp\htdocs\adminer\compile.php on line 4
可以看到, 在php7.2下, 已经非常严格了.
count函数仅支持参数为数组, 非数组情况下将报警告. 我们可以修改为:
- if(is_array($arr)){
- count($arr);
- }
- // 问题来了, 为什么count函数不自己内部判断一下呢?