Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122733 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 3E0A11A009C for ; Fri, 22 Mar 2024 20:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711137997; bh=o+GtmR9zAaI2Ou1R7sQM1LTAAdPfawUyEB0ZNNRRrBc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KC+AS3J9936d1imU4nWPRhLgZPZIiDQVOfzr9UK7aAC+L3T2tXCMGjslmb1J0f43O jlh7UFM1D/mrV/3/CGH94Xb3hI+fPEvgEZD+p9pVk8dEJXb90bjqjbAwxr7rZzEFHi JNgwWvGaLSfSHf0FjKS6W+01BjS6CnHa4HuMmdQZZpee6z5vesNZ0jWmtjzxu3cofj 6CCm5LxL7vB3UIYp4c6LdJzSx2vhu+/1m7zr9rDjo6vIPv+G7RJvbdzg2YBBhrCIhv N0WGVmgkr5IN+XuLYhVdBV6cBmX4/YSQcXECI6XxsEObFub4zQ0r2SZ7jjuWTFcKMh J6f/MDaToeEZA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB0D3180078 for ; Fri, 22 Mar 2024 20:06:33 +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_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 ; Fri, 22 Mar 2024 20:06:33 +0000 (UTC) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5a49261093cso1204178eaf.3 for ; Fri, 22 Mar 2024 13:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711137970; x=1711742770; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=o+GtmR9zAaI2Ou1R7sQM1LTAAdPfawUyEB0ZNNRRrBc=; b=g5hSi7skMJJtIZoaiMJ7aolMJKN2xpJIMcOyHLF4VtxEie11Qr1IGsyAb7E9Iv0KVL TlXHL0MZ0dcskddEbK3tmvaw53FtnLAeq6j6FV99JFSLORCLwwFvAP/V3XCIkgEfcC2Y 41YG6UQfP5ZacTuO1XdMJgiCGhftp1Pd5cc72WNGkB49cmRUOoR2U/akRj0ipQEMU35J fM96DtPTiH8/53kqeqNm+Urj7g0QTEgaWNj8d43v5wGX6bkkEXYm8sPd4gmwvVAfvyVh MYsG5PBZU/oCSkMEz9P4myZstiVkovnr5/Kvc6oADzwoaYmiBJVW8zTyh4+zK+4vgjnq jA8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711137970; x=1711742770; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o+GtmR9zAaI2Ou1R7sQM1LTAAdPfawUyEB0ZNNRRrBc=; b=USRxaQLMTDOdKus+ratl3mpVczRyRMESxQ5wVi1aPaOMP3tSepJ8IZQQ0XW45nOqVP oarIP9yazhMY/b2K3HGpOY9f+2bpc13RWZgi8woYjFKWFLem88U2h4JtdDrpK7DTaGmt 7lfKC2kHjy67FTZ2+DfOQdpoYvHHnMCH7+vK0YwzA55n6FArrb1q1DUB2gHDD9jTgwX8 ZJuSRmsjdiWoKBjIcJimJXiLnOyX22cTUaGbTYHMK5rqLZHzhtZXNMh+/yHN/eAzmW/Y S1UyAnv5C9HW4MQHs8SCNos2+AKexdBoHdbYuZSFzAwl/J4KhC3K1NuyaQMEOxaQbuzZ /k1A== X-Forwarded-Encrypted: i=1; AJvYcCVV9JJ4Z4Z+QaKHyRAHYL47z/EIsashIVcXD1hS/gfmLOt8QjLpeDhWpQ6zlGXuDxX9QwyPo0KTAP3MiOaCXrquQ//l5g+7zQ== X-Gm-Message-State: AOJu0YwsWq/oS7TFv7jyAG36GNlRz7lA6ZHkWCFIwJpM7L0cxnwOlBi3 2XXrsoLHVN6J96WtnO2jQmTHng/TwfwyxLK+4syeW7/n4lLuW94bxVr1hrQKqYpycDuW3BHRLDS 5gnBFw7ZzJ2eKYCTa3fwLgiQE3hk= X-Google-Smtp-Source: AGHT+IE7Xpel7gbd0JsL5OkR5De9XRqkzPqECoxyk5RPgyiKRNoaz9/hPJZFzo+lKWIKdqu1vPsVLhDiQJwUyb6PONQ= X-Received: by 2002:a05:6820:98c:b0:5a5:2714:7df5 with SMTP id cg12-20020a056820098c00b005a527147df5mr720120oob.5.1711137970444; Fri, 22 Mar 2024 13:06:10 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <3F78A125-1946-42E2-A4F5-A2B282BE2107@rwec.co.uk> <2d7ec203-6e80-445c-94f4-d29ef58743b1@rwec.co.uk> <7d53f2e4-46f3-46f1-89b0-6e1d3b0b2e32@app.fastmail.com> In-Reply-To: Date: Fri, 22 Mar 2024 21:05:58 +0100 Message-ID: Subject: Re: [PHP-DEV] Proposal: AS assertions To: "Rowan Tommins [IMSoP]" Cc: Claude Pache , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Fri, Mar 22, 2024 at 8:02=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On Fri, 22 Mar 2024, at 17:38, Claude Pache wrote: > > > Le 22 mars 2024 =C3=A0 16:18, Rowan Tommins [IMSoP] a =C3=A9crit : > > $optionalExpiryDateTime =3D $expiry as ?DateTimeInterface else some_other= _function($expiry); > assert($optionalExpiryDateTime is ?DateTimeInterface); // cannot fail, al= ready asserted by the "as" > > > I think that the `is` operator is all we need; the `as` operator adds syn= tax complexity for little gain. Compare: > > $optionalExpiryDateTime =3D $expiry as ?DateTimeInterface else some_other= _function($expiry); > > vs > > $optionalExpiryDateTime =3D $expiry is ?DateTimeInterface ? $expiry : som= e_other_function($expiry); > > > > I agree, it doesn't add much; and that's what the draft RFC Ilija linked = to says as well. > > But the point of that particular example is that after the "is" version, = you don't actually know the type of $optionalExpiryDateTime without looking= up the return type of some_other_function() > > With the "as" version, you can see at a glance that after that line, $opt= ionalExpiryDateTime is *guaranteed* to be DateTimeInterface or null, which = I understood to be the intention of Robert's original proposal on this thre= ad. > > -- > Rowan Tommins > [IMSoP] > Indeed, "as" is to pattern matching like the fn is to function. You can live with one or the other, but having both is much more useful.