Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127808 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 lists.php.net (Postfix) with ESMTPS id 18FCC1A00BC for ; Mon, 30 Jun 2025 16:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751299258; bh=k1JxyrSrhMlDHNkWZVMSmxkZWn5UPd6GIyUKqVIEUgs=; h=From:Subject:Date:References:To:In-Reply-To:From; b=IgeR3nzZTbLSxgEk28oTs5ufyn9NwU5vU2T/BMMHgubQkTQ4RIg2YYsgiTc0Vpe2X aWJagoTXZMnD3NOZNLKjKLi4JC5L863Pf3fIsf0IzxSzCLKrxUJNZC0SJIaGMnaqA2 kucxFbbHDiHbhPLfsSFd3VJXr4t261xh3Lz2xp5Yr9wpxRqISr72NaMV/zf+KdpiCw HOHvsYS/LelcxGjaJVzDtJ8KXCYhrOv6T4G7kHP054ELxDasbSwHgmP12adheY8xlj iiSwPVA3CTQ/bIiGlphWLmr7Ta4YJzMG9fM6cbX1tYmgMu/ZYzEx2qwo4UxX7krXRt E3Ea0HJ/U39ag== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 32112180382 for ; Mon, 30 Jun 2025 16:00:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_40,DMARC_NONE, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 30 Jun 2025 16:00:56 +0000 (UTC) Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-70e4043c5b7so21762587b3.1 for ; Mon, 30 Jun 2025 09:02:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751299370; x=1751904170; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1uSX/Dh6lz2mvAp2tsPLSp5Pc1LW2J+3cscRD1Q6B6w=; b=kEJXypYxjP7NXagxUfEaTG4P77p1Vh4yaVUsy8jWNHt7SemEM9D5gIqOEFYnRL1G3C LCbvHMHZcCI2rCnrTFXGJtTXBIQu4QSbg50e8F/Hl6qC5END6ehRyyAulHDyAAyIj/yp bBS5q3Pp+UODV0NYFpzCdMJZOVZ/vCZlqaM0O8hQ4X688NpN4tpdlNVEqQRsEEZBXvRw o/EqT8U95FGJKqBoUvJHsnCQgSt3jfT7mVABDRgKIzHutp+AdhEy7Q+s3gZyoc7tSwo7 N7ApI2rL8YYOaF7jGrVATtwCijLQLLkgSfnQh3ORyPvEo62uILjsaZhHNqq9lNyaXFH5 R22g== X-Gm-Message-State: AOJu0YzLuSZPR0KbSlqzAN3jBNvXjmT0INJ3iYJVlSBL7D2iqUnVUE10 umNdKxujGam9vkHN+icsvm4gvE1g+G2Zl8leATBZ5+QMl14iqj9HRA8ooFPT8YWq//pRBMFV0Cq CCfCvY9TT X-Gm-Gg: ASbGnctGOQSKq0I0+YQJfBsRuZA/g/9PZwRaPh7aN/8z3KjgOLlPTZuFApUn4ablii/ soZCOX8Ra18pYupRvLtqMjKK9Lpg5fax31JVNaEu2VGSjnArOoQ7ZhkMviLmv5S1qoTr1o+nrMW m/ccKv0+2DJSTGJJY3fh/CDSdFTG+FgYtPpAe43rPgc4WiWh9yJifKMX4m+XasrxNjfASFauhAp kNdlf1F2SQ8AZuV3Pfz1NyK53t+394iEPpp81NLgio49Vk7lf7RziQUt7CUD/as/PZJjt9F4fMv Yss8KHDmdwV7I6ncRnP8C9K3FD47rS6CueZYUr0U74u1SR1uoji2N8aCBJgg7/750F6+YbLE9N8 ihTKobnPNihUm/uiHkRbrYlSsjWt2dpLl9qbS1TaDCMbTEKL2lw== X-Google-Smtp-Source: AGHT+IFccCcbxeklyykqxsltwhyC1yLzZ3IXQ3RYfWF/tH96YhH7Od+28Lxa9FexZNge/9BOMd3FIw== X-Received: by 2002:a05:690c:9b10:b0:70e:7882:ea8e with SMTP id 00721157ae682-715171a36damr216746357b3.31.1751299369388; Mon, 30 Jun 2025 09:02:49 -0700 (PDT) Received: from smtpclient.apple (h96-61-170-179.lvrgtn.broadband.dynamic.tds.net. [96.61.170.179]) by smtp.gmail.com with ESMTPSA id 00721157ae682-71515c8f5afsm16029477b3.79.2025.06.30.09.02.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jun 2025 09:02:48 -0700 (PDT) Content-Type: multipart/signed; boundary="Apple-Mail=_CE91984A-912F-47A0-BC55-ED2CFEAABF0D"; protocol="application/pgp-signature"; micalg=pgp-sha256 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 \(3826.600.51.1.1\)) Subject: =?utf-8?Q?Re=3A_=5BPHP-DEV=5D_Request_for_RFC_Karma_=E2=80=93_kha?= =?utf-8?Q?ledalamxyz?= Date: Mon, 30 Jun 2025 11:02:37 -0500 References: To: PHP internals In-Reply-To: Message-ID: <92E75FAC-70EA-46C1-AAFC-CC423A2BE77F@php.net> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: ramsey@php.net (Ben Ramsey) --Apple-Mail=_CE91984A-912F-47A0-BC55-ED2CFEAABF0D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 30, 2025, at 09:52, Khaled Alam = wrote: >=20 > Hi Ilija, Ben, and Thomas, >=20 > Thanks for the rapid feedback. You=E2=80=99re right that PHP=E2=80=99s = existing expression-throw idioms cover some use cases, but `=3D>!` fills = three gaps: > 1. Comprehensive =E2=80=9Cfalsy=E2=80=9D check =3D>! consistently = treats all PHP-falsy values (null, false, 0, "", []) as failure, in a = single, unambiguous operator.// Existing: must choose between ??, ?:, = ||, each with its own quirks > $name ?? throw=E2=80=A6 // only null > $name ?: throw=E2=80=A6 // also empty strings and "0" > $name || throw=E2=80=A6 // can=E2=80=99t embed in function call >=20 > // With `=3D>!`, you get exactly =E2=80=9Cfail on any falsy=E2=80=9D: > $name =3D>! throw new Exception("Missing name"); You mention =E2=80=9Calso empty strings and `"0"`=E2=80=9D as quirks of = ?:, but the argument you=E2=80=99re making is that `=3D>!` fails on = =E2=80=9Cany falsy.=E2=80=9D Empty strings and `"0"` are part of =E2=80=9C= any falsy,=E2=80=9D so I=E2=80=99m a little confused about the = distinction you=E2=80=99re making here. > 2. Value forwarding > All of the above patterns discard or ignore the original value when = used inline. With =3D>!, the guarded value is both asserted and = returned, so you can write: > // Inline validation + use in one expression > sendEmail( getUserEmail() =3D>! throw new Exception("Email required") = ); > This both throws on a missing/falsy email and =E2=80=94 when valid =E2=80= =94 passes the exact email string through to sendEmail(). I don=E2=80=99t understand the distinction you=E2=80=99re making here, = either. This seems to work currently with ?: See here: https://3v4l.org/YMLT1#v8.4.8 ``` function getUserEmail(): ?string { return 'foo@example.com'; } function sendEMail(string $email) { echo "Email address is $email"; } sendEmail( getUserEmail() ?: throw new Exception("Email required") ); ``` Unless you mean it also *returns* the falsy value, which in this example = doesn=E2=80=99t have much value, since it throws an exception, = disrupting program flow. > 3. Clean, declarative syntax > Because it=E2=80=99s a dedicated operator rather than a hacky boolean = trick, =3D>!: > =E2=80=A2 Reads as =E2=80=9Ctake X, or fail=E2=80=9D in one = glance. > =E2=80=A2 Avoids parentheses gymnastics or confusing operator = precedence. > =E2=80=A2 Encourages fluent, lets you chain guards: > $userId =3D $input["id"] =3D>! throw new Exception("ID missing") > =3D>! isValidId(...) =3D>! throw new Exception("Invalid ID"); You=E2=80=99ll need to explain the =E2=80=9Cfluent=E2=80=9D behavior in = more detail. The way I read this is: if `$input["id"]` is falsy, throw = an exception for the missing ID. If it=E2=80=99s not falsy, however, it = should proceed to the `isValidId(...)` call, passing it the value. So, = if the left hand-side is non-falsy, it skips over the immediate = right-hand side? If it skips over the immediate right hand side when the value on the = left is non-falsy, then when it encounters the next `=3D>!`, the = left-hand side is still non-falsy, so it shouldn=E2=80=99t attempt to = call `isValidId(...)`, right? > Demonstration: >=20 > This was primarily an exercise to familiarize myself with the = internals process. I=E2=80=99d love to gather feedback - and some = RFC-karma - before drafting a full proposal on the mailing list. > Thanks again for your time and guidance! Keep it up! Don=E2=80=99t let our criticism discourage you. :-) A couple of pointers: 1. Don=E2=80=99t =E2=80=9Ctop post=E2=80=9D on replies to the mailing = list. 2. It=E2=80=99s generally not a good idea to include images attached to = mailing list messages. Cheers, Ben --Apple-Mail=_CE91984A-912F-47A0-BC55-ED2CFEAABF0D Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCaGK1HQAKCRCwLZeYnIwH G9xvAP4mNVttEiaQC7w0FJbOBWp6TOSx4qOnIMs7UZ8pca+00wD+OUx9YdUmn9b9 sQ9K7IpJep7uF8UZFnRFoF1IJ9eEbbI= =JFQA -----END PGP SIGNATURE----- --Apple-Mail=_CE91984A-912F-47A0-BC55-ED2CFEAABF0D--