Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118520 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25870 invoked from network); 26 Aug 2022 18:42:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2022 18:42:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9B1B3180545 for ; Fri, 26 Aug 2022 11:42:21 -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=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS208722 37.140.128.0/18 X-Spam-Virus: No X-Envelope-From: Received: from forward500o.mail.yandex.net (forward500o.mail.yandex.net [37.140.190.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 26 Aug 2022 11:42:20 -0700 (PDT) Received: from myt5-2f5ba0466eb8.qloud-c.yandex.net (myt5-2f5ba0466eb8.qloud-c.yandex.net [IPv6:2a02:6b8:c12:1c83:0:640:2f5b:a046]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 34BD1941B52 for ; Fri, 26 Aug 2022 21:42:18 +0300 (MSK) Received: by myt5-2f5ba0466eb8.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id 9GouQl7GHE-gHiCSai7; Fri, 26 Aug 2022 21:42:17 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=php.watch; s=mail; t=1661539337; bh=3QTZV9CZNIZ+g5lPx/Nlt1WPE/P1bCSX1TB+xVNLBsY=; h=To:Subject:Message-ID:References:Date:From:In-Reply-To:Cc; b=EQZSMe6eOUcTZqf9twSp5b9G5cJXcuvEp975YE1w9hw/Urg2ypf5fCeIuHtAxFlAh lAIzVkqNeHKJUMs80QAZ/DShdNImKE3hmzBtWKrwKDKSKSLMJ7EHefEBIMKWOjic5O gzRiKXA2qDCdRx5ph0oqtI681YfsKAbc6aOmHn8s= Authentication-Results: myt5-2f5ba0466eb8.qloud-c.yandex.net; dkim=pass header.i=@php.watch Received: by mail-qk1-f173.google.com with SMTP id b9so1799654qka.2 for ; Fri, 26 Aug 2022 11:42:17 -0700 (PDT) X-Gm-Message-State: ACgBeo0P9434yrOtlJUmZhCVlAP6+AXKMLVHxaC1byeXtJgksTh3JGg1 UPvZxb00LrIhhZ5rEd/e835WKIyPvX/IaK8t3v4= X-Google-Smtp-Source: AA6agR7VLe0vY7ezPOjguv0DCG6ZaQ8n0GesUhKfzkWAjf2gk1k5AXQQH3z4KWL1G+xc/JOweyZIrCshzJs6T4pKGaE= X-Received: by 2002:a05:620a:688:b0:6bb:29aa:4ce4 with SMTP id f8-20020a05620a068800b006bb29aa4ce4mr792435qkh.18.1661539336085; Fri, 26 Aug 2022 11:42:16 -0700 (PDT) MIME-Version: 1.0 References: <8D53AD5B-7CFC-4820-9EE4-FEB365D327A8@woofle.net> In-Reply-To: Date: Sat, 27 Aug 2022 00:11:49 +0530 X-Gmail-Original-Message-ID: Message-ID: To: David Gebler Cc: Kamil Tekiela , php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC json_validate() - status: Under Discussion From: ayesh@php.watch (Ayesh Karunaratne) > 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. As for exceptions, I too think throwing an exception here is an anti-pattern. It makes perfect sense to throw on `json_decode` if the program doesn't want to deal with invalid JSON gracefully. But calling `json_validate` is an intended call, and returning an error is excepted, and not an exception.