PHP 7.3新特性
1、json解析出错提醒
json_decode("{"); json_last_error() === JSON_ERROR_NONE // 这个返回false json_last_error_msg() // 但是这里返回 "Syntax error"
php 7.3中针对这个问题进行了修复,增加了JSON_THROW_ON_ERROR
use JsonException; try { $json = json_encode("{", JSON_THROW_ON_ERROR); return base64_encode($json); } catch (JsonException $e) { throw new EncryptException('Could not encrypt the data.', 0, $e); }
2、增加is_countable
以前的php我们如何要检查某个对象是否可以进行count要这样写
if (is_array($foo) || $foo instanceof Countable) { // $foo is countable }
但是现在更简洁了,好记了
if (is_countable($foo)) { // $foo is countable }
3、增加了array_key_first(), array_key_last()
以前我们要知道数组的第一个键与最后一个键,要循环数组,非常麻烦,现在更简单了
// usage of an associative array $array = ['a' => 1, 'b' => 2, 'c' => 3]; $firstKey = array_key_first($array); $lastKey = array_key_last($array); assert($firstKey === 'a'); assert($lastKey === 'c'); // usage of a numeric array $array = [1 => 'a', 2 => 'b', 3 => 'c']; $firstKey = array_key_first($array); $lastKey = array_key_last($array); assert($firstKey === 1); assert($lastKey === 3);
4、抛弃image2wbmp()
5、抛弃大小写敏感define
网友评论0