Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100068 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33047 invoked from network); 28 Jul 2017 07:01:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2017 07:01:05 -0000 Authentication-Results: pb1.pair.com header.from=giovanni.g@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=giovanni.g@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.180 as permitted sender) X-PHP-List-Original-Sender: giovanni.g@gmail.com X-Host-Fingerprint: 209.85.217.180 mail-ua0-f180.google.com Received: from [209.85.217.180] ([209.85.217.180:35001] helo=mail-ua0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/E1-32841-F20EA795 for ; Fri, 28 Jul 2017 02:56:47 -0400 Received: by mail-ua0-f180.google.com with SMTP id d29so147839605uai.2 for ; Thu, 27 Jul 2017 23:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Jkng/0zqU0iv0N34VIvs5y3+ZKMbNFpTxOD5Evxf0zY=; b=ebO9VEOkN3nQkFHpnpm9YU90kAtTwA2PRQLZc7HP7vu9nZjZ6jvdIrGRvkG1+RvxFQ 3527q89u8fAz5BvY7K0GbPvYHn6fVJIRbvlkGD+xxeuvfxeH2e/44uHX7E7hyrwnnz91 miHUT9RAnP1XZA/HW/HGyui83mzN2sdfSqRRuDw2+QkX0d4wfNR7lY4qAh/ogNEWe6SX Vk1mpCae0F7+fTb/tzMJWPA9EeqhD1BBXtfbhv3kHZJ2m7BIi2d2FoEraZFb5IthFieN 6KwUYtgrFZ05Zbunf38jLBT3m5MeuYt5msW4/5JocD8rMZEQozhpjYTbcgRdFqU4T94c 8qBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Jkng/0zqU0iv0N34VIvs5y3+ZKMbNFpTxOD5Evxf0zY=; b=n7hqaGyPY0lYnoMqkoLfxAfqC4135+JSTrFwiJ6qDjwzJVbRXtjS51uk2OeiD4RYfe mFMiGSR9peHkXp1ehUIk4363BrRZzqd4XtHG3f/NTBWtLRf316ynZKnPUCZ/fTXyrUVQ f+/KQfWcmtS1bnLt8AMzavAF0z+cZc/cWGN50Bmdc/wgHBfVAM5QwLPlcll/Xx6uyjue kccSBTgIZEi5z1tEMogolWNeftjbHS4cioWIhqzUQ/4jqfeQAPXbxzLOp3YGmN3JPW9P By8c6bVmRsc3Ay3KRu2R3lqUUhyflVnO0HN1ySLzZKxtfXy3SeLn8mbXgMAbQwqzMOyl tpjA== X-Gm-Message-State: AIVw110BjrvjyC4+e93WL6YgGyurJ16Vq0CKYTo7YyrbSWUxPD84tkqA GegDrHNj4uDsbBnqg/v+V/rSUB5bqA== X-Received: by 10.176.18.217 with SMTP id o25mr3949556uac.77.1501225004533; Thu, 27 Jul 2017 23:56:44 -0700 (PDT) MIME-Version: 1.0 Sender: giovanni.g@gmail.com Received: by 10.103.148.1 with HTTP; Thu, 27 Jul 2017 23:56:44 -0700 (PDT) In-Reply-To: References: Date: Fri, 28 Jul 2017 08:56:44 +0200 X-Google-Sender-Auth: QMWuPTBlwpMlc0qZUedC41yRAl4 Message-ID: To: Craig Duncan Cc: Niklas Keller , Internals Content-Type: multipart/alternative; boundary="f403043613de1f8d1205555b2f64" Subject: Re: [PHP-DEV] json_encode() / json_decode() warnings From: giovanni@giacobbi.net (Giovanni Giacobbi) --f403043613de1f8d1205555b2f64 Content-Type: text/plain; charset="UTF-8" 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. -- Giovanni Giacobbi --f403043613de1f8d1205555b2f64--