Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100069 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33068 invoked from network); 28 Jul 2017 07:01:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2017 07:01:06 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.161 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.161 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.161] ([81.169.146.161:34962] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/E1-32841-DE0EA795 for ; Fri, 28 Jul 2017 02:59:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1501225195; l=5033; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=dcYLTF3XP5hGeWnyQCHSg8KVH//MxlD/dZG8/Z/17P4=; b=xcoojPS7XIBR02nGKrWip1s/UEpsIZyHEmAmSM8sGKUlP+7gyJyQqLd8XyAXusx2kb T+s85OP2PHVW9ObVMkSU0ummXaI0apBhYiaVgw752P8NYQoUNCVXUObFqcf069UnXQl5 E+UMwsO2N0M6Q4zGeWpkEhWN7/lcsQjkJ62Q0= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLDup6E67mzuoNHBqT83Q== X-RZG-CLASS-ID: mo00 Received: by mail-oi0-f54.google.com with SMTP id g131so126181461oic.3 for ; Thu, 27 Jul 2017 23:59:55 -0700 (PDT) X-Gm-Message-State: AIVw111sZGo2q51FjZXsSvuSeF8GlxKyVoF4lBWYkZpIM+JaxvxfLFQ4 jtmPjdvW0+wIa5m66n9B3ZgGDexcpw== X-Received: by 10.202.190.65 with SMTP id o62mr1593236oif.42.1501225194479; Thu, 27 Jul 2017 23:59:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.154.167 with HTTP; Thu, 27 Jul 2017 23:59:54 -0700 (PDT) In-Reply-To: References: Date: Fri, 28 Jul 2017 08:59:54 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Giovanni Giacobbi Cc: Craig Duncan , Internals Content-Type: multipart/alternative; boundary="001a113d706271ea3005555b3a62" Subject: Re: [PHP-DEV] json_encode() / json_decode() warnings From: me@kelunik.com (Niklas Keller) --001a113d706271ea3005555b3a62 Content-Type: text/plain; charset="UTF-8" 2017-07-28 8:56 GMT+02:00 Giovanni Giacobbi : > On 27 July 2017 at 18:00, Craig Duncan wrote: > >> On 27 July 2017 at 16:57, Niklas Keller wrote: >> >> > It should rather just throw exceptions. Warnings do not really allow >> error >> > handling, they just allow error reporting. >> > >> > >> Agreed, but I can't see Exceptions passing the vote. Warnings can be >> silenced by those that don't care and converted to Exceptions by those >> that >> do >> > > Error management is a painful topic in PHP, expecially when considering to > the way fopen() behaves, where you *need* to use the "@" suppression if > you want it to behave the way you expect it to behave. > > About Exceptions you can easily build a framework around core functions, > for example this is in my core library for all projects: > > ```php > function safe_json_decode($json = null) { > if ($json == "") > return null; > > $retval = json_decode($json, true, 512, JSON_BIGINT_AS_STRING); > if (json_last_error() != JSON_ERROR_NONE) > throw new JsonDecodeException(json_last_error_msg(), > json_last_error()); > > return $retval; > } > ``` > > So yes, the behaviour of json_decode() might not be optimal, but it's fine > the way it is. > Yes, I know. There's https://github.com/DaveRandom/ExceptionalJSON. While the current API works, I'm not sure whether I'd say its fine. Regards, Niklas --001a113d706271ea3005555b3a62--