Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125323 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5D2E71A00BD for ; Tue, 27 Aug 2024 15:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724771146; bh=LTpP4Sh0b00hJsiSGaTLlJI8IbLlQv+FaQFzycSEbCw=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=PpqIK0Gzw4JAnCizlUEwTo2NJAN0rK7qiJkoa/FZR4jG6Z7WheMijf4f/7hBO14Gy Tg5/qJgSxRky9PC0rlL4danzL/ZQD3PphmrWKF7Pt8G9sXoAU3y/O6+udFag6HcB+W wn9QJZoW4ZILhNuI8aqgJolwJCO9rmY1E+igUH9UPPmEeFGeRy1pZWwPJr2f1nuTe4 tb2KYpye0k682qFO66VcPdkb/TYJWysCsklrLkiSmLrbzBJtUumEckMlp/YEzrjyBY ZFepsjN2XdSTr9TBFwDZ8wA+hXvIUvMVy4c1xN6cgIzO56OgatnAMqlKHLKj9Tjxar 7HUQFTbXmKv4w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E0E3B18003E for ; Tue, 27 Aug 2024 15:05:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (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 ; Tue, 27 Aug 2024 15:05:45 +0000 (UTC) Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 4D442202F2C61; Tue, 27 Aug 2024 11:03:51 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 nebula.zort.net 4D442202F2C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zort.net; s=zort; t=1724771031; bh=LTpP4Sh0b00hJsiSGaTLlJI8IbLlQv+FaQFzycSEbCw=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=YjszRA8aMV6CA5IKk15EuqrJjhPvoudoaYwtstYZUtRaEN/8F2jTrRfl0X3mmd6JX 5pneBNncUqXivIj1lE054x108iLGdHZvGHyavfeO6LTU60+f+iNU//gpWbeXnzeoVP Q6awMOTPeFazhhmT2dv3LpKTigk9/1ewF1T1tSY8= Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [PHP-DEV] [RFC] Default expression In-Reply-To: Date: Tue, 27 Aug 2024 11:03:40 -0400 Cc: internals@lists.php.net, Bilge Content-Transfer-Encoding: quoted-printable Message-ID: References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> To: "Rowan Tommins [IMSoP]" X-Mailer: Apple Mail (2.3776.700.51) From: jbafford@zort.net (John Bafford) > On Aug 27, 2024, at 10:14, Rowan Tommins [IMSoP] = wrote: >=20 > The only expressions that are in some sense "safe" are those that can = apply equally to any possible type that the function could in future set = as the default. In theory, that includes a match statement with an arm = of "default =3D> default", e.g. >=20 > json_encode($data, default, match(gettype(default)) { 'int' =3D> = default | JSON_PRETTY_PRINT, default =3D> default }); >=20 > Apart from being incredibly hard to read, that's not even useful: the = aim is to always enable pretty printing, but the result is "enable = pretty print, unless the type of the default happens to change". I'm not sure this could even work at all. The "default" parameter to = gettype() isn't the default value of the third parameter to = json_encode(). It's the default value of the first parameter to = gettype(). Which would probably fail, since gettype()'s first parameter = doesn't have a default. I suppose this could be solved by specifying an = offset or label (e.g. as with `continue 2` in a nested loop), but that = would just make it even harder to read. -John