Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100062 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86273 invoked from network); 27 Jul 2017 15:57:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2017 15:57:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.162 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.162 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.162] ([81.169.146.162:31482] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/11-10671-77D0A795 for ; Thu, 27 Jul 2017 11:57:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1501171060; l=2724; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=ZWeIfYxDCQeJPOxRCu/ozfyJiMQJDjySCd5tA/6xgNQ=; b=uv/Mgr7Oe4ROIOiMzeoyVcfdYTXvyZw5Zw6WgmE27MBhfy/QVwenAVGck4CcEeke12 EcC7UvlnXOJmGUudEV7VRi8HILsU8B0nDK/m+jk3opr+i6CU8y9cuad6yyx5pJC+lbDM RSiFYOur69VszZjyyONhPuPPWgwS/uVJc1MqU= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLDup6E67mzuoNHBqX+3Q== X-RZG-CLASS-ID: mo00 Received: by mail-oi0-f46.google.com with SMTP id g131so110913865oic.3 for ; Thu, 27 Jul 2017 08:57:40 -0700 (PDT) X-Gm-Message-State: AIVw1113KngFZpBSDSAdKahtrSSzwZMX1TgxBkQ8vff8SvkBg+/NfG3i ntDCxGDtq/MzYCvaksg6F7BSPhSp3Q== X-Received: by 10.202.205.209 with SMTP id d200mr4665832oig.304.1501171059496; Thu, 27 Jul 2017 08:57:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.154.167 with HTTP; Thu, 27 Jul 2017 08:57:39 -0700 (PDT) In-Reply-To: References: Date: Thu, 27 Jul 2017 17:57:39 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Craig Duncan Cc: Internals Content-Type: multipart/alternative; boundary="001a1134e218bfad9805554e9fe7" Subject: Re: [PHP-DEV] json_encode() / json_decode() warnings From: me@kelunik.com (Niklas Keller) --001a1134e218bfad9805554e9fe7 Content-Type: text/plain; charset="UTF-8" 2017-07-27 17:41 GMT+02:00 Craig Duncan : > Hi internals, > > When using `json_encode()` and `json_decode()` it is required that you > manually check for errors after every call, eg: > > ```php > $data = json_decode("false"); > if (json_last_error() !== JSON_ERROR_NONE) { > throw new UnexpectedValueException(json_last_error_msg()); > } > ``` > > This isn't _that_ unusual in PHP, however normally in these situations a > warning would be raised. But the JSON functions only raise warnings in a > couple of scenarios, most issues are completely silent. > > I wanted to begin a discussion around changing this, so that warnings are > raised for any issues during `json_encode()` and `json_decode()`. > > I have an implementation ready and I'm happy to draft an RFC if this > suggestion doesn't receive universal hatred. > It should rather just throw exceptions. Warnings do not really allow error handling, they just allow error reporting. Regards, Niklas --001a1134e218bfad9805554e9fe7--