Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118523 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40562 invoked from network); 26 Aug 2022 22:33:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2022 22:33:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE4F41804AB for ; Fri, 26 Aug 2022 15:33:49 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 26 Aug 2022 15:33:49 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 66BD45C0239 for ; Fri, 26 Aug 2022 18:33:47 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 26 Aug 2022 18:33:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1661553227; x= 1661639627; bh=WZRQ6NLe+xn6f0hShGif9dTZIJA8lmi2juVmR3zxuW8=; b=N HtDsWB79GpXHzIbww/YtdcVLygxPSVR9r3xiYRutXGrBGoMLQyLVYZScZuR+VxF/ vc/TY5yn31DtMZbY/QQdf2rmp2u9y5OxDuGeFx1jF31lgzDveXN8mm8lGxbr9gPS vu9X+MI4ELAUtLtfdD7OVVWQIKBsT84LmSRxNYclbNlCQExg85GGffgA6cFvAJfU wVTv4tW9B/KVKdLK/5589DeFe4+Nk0z5kBury/zaxHlO4azkeq1bzWmqkWqCdvCn HkY5k3PoDgSF2IBYytfeQyrXEIAKbcJ12+QwaX6ObZGvdKtjvaB/fWAIhXkiBKqs KU1hK0tKlRuAO8fuB8HSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1661553227; x=1661639627; bh=WZRQ6NLe+xn6f0hShGif9dTZIJA8 lmi2juVmR3zxuW8=; b=vUMvK90wzOYvy9pi+mc49D/lKjpRb44jI2komRb0vDlq z/0ZcguNyXK+n6qiA+2WwDw01L3roRoNyaCr46K8/A0Ku6eEbaWae2uu6zJIxIBv +boB8Gwqtdv37ON9TWW/1dffUdW/cWMAj9ziR5+UQmwZN//Qj4qZMRp3P54z7L4T AN+bMasI5tqwf3chIrPDft+y6xrBQgy5U80WmB7ADdu4u113lJ2XmzQnb3eKbj00 3EzqvgQPNUevhwAwJdQSEt4L6o7vmSw+Itxut19zoSH4hadUD92pNmDjC1BhSEFU rLJjhMSpgApfpU4JThMJ8G0/OLw5IJ6OvMRpyUIrAg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdejiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeejlefgvdegkeeutdffvdegieegueetffejueekvdeu veeifeeuudelgfduteefgfenucffohhmrghinhepphgvrghkugdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 252781700082; Fri, 26 Aug 2022 18:33:47 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-841-g7899e99a45-fm-20220811.002-g7899e99a Mime-Version: 1.0 Message-ID: In-Reply-To: References: <8D53AD5B-7CFC-4820-9EE4-FEB365D327A8@woofle.net> Date: Fri, 26 Aug 2022 17:33:26 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] RFC json_validate() - status: Under Discussion From: larry@garfieldtech.com ("Larry Garfield") On Fri, Aug 26, 2022, at 1:41 PM, Ayesh Karunaratne wrote: >> whether returning boolean is the right thing to do at all. It seems obviously >> intuitive it should, returning true for valid and false for invalid JSON >> but then if you consider you're still going to be in the situation of >> calling json_last_error() if you want to know why invalid JSON was invalid >> and in particular you might not expect the "last error" to have changed >> just from an attempt to check a string. How can there be an error when by >> definition you weren't trying to do anything except check the validity of >> some unknown data? Not sure what the answer is there...curious what other >> people's views are on that. I don't think throwing an exception on invalid >> JSON is the right answer in any case. > > One of the reasons why I like `json_validate` over `is_json` is that > the former does not imply a boolean return value as strongly as the > latter. > > I think we should not modify any state with the `json_validate` > function, and I'd be happy with the function returning 0 for a valid > JSON, or the error code as an integer (`JSON_ERROR_STATE_MISMATCH`, > `JSON_ERROR_SYNTAX`, etc.). `JSON_ERROR_NONE` constant is already > assigned 0, so they align quite well too. The problem here is that you're using a falsy return (0) to indicate "it validated", which is logically true. PHP's type juggling makes that a very bad idea. I somehow doubt it will get much traction, but this is the sort of case where a "naked either" approach could work well: https://peakd.com/hive-168588/@crell/much-ado-about-null Though there's also the risk then of all objects being "truthy", since there seems to be no appetite for a __toBool() method as that's been shot down before. At some point, we need to realize that our current design philosophy boxes us in on too many sides and something is going to have to change. I see the argument for json_last_error() not being a great fit, but given the limitations we've chosen to have in the language it seems like "return bool and use json_last_error()" is the least-bad option. --Larry Garfield