From 7ff8b7bb574546395eff1854d5aca806928a1fee Mon Sep 17 00:00:00 2001 From: WeakSun Date: Tue, 21 Jun 2016 14:35:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=A9=BA=E6=A3=80=E6=B5=8B=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=BA=E7=A9=BA=E5=AF=BC=E8=87=B4=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 防止array和object类型数据为null时,导致调用发生异常。 --- library/think/Model.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7b7fc3f1..02ca0dad 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -391,11 +391,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = date($format, strtotime($value)); break; case 'json': - case 'array': $value = json_decode($value, true); break; + case 'array': + $value = is_null($value) ? [] : json_decode($value, true); + break; case 'object': - $value = json_decode($value); + $value = empty($value) ? new \stdClass() : json_decode($value); break; case 'serialize': $value = unserialize($value);