Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122703 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 462C71AD8F6 for ; Wed, 20 Mar 2024 23:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710975944; bh=G1mKN3eyU/MYougRDnOzZoavv/RM2Xkeho1nPiYLujM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lNjkfyc6ZA8fV+UgABD5MdFvfseLeNGj7yd/U6E9+hmFdWMsoE9xI8ziBM0340E1i IUEgINpZ/7KOdyUQDDpMG85opKRxmVYfMba0ojQjWAZWTMD4EtqDUDJKA8zuyh+Pjg aOVQYwrVtAIFmLVxJZCXeKkm0Cxtvc+4RCC8XFd9WyxC6MiKyFkhFxgqEHTEw9TOlN 9zNblncgEOif7058DpBvmIqsYkhVvwSsUmXqMthSBqXGs8BQpmsSta5/3L0G7ptYq+ Ib2Yc1uAvdffmGkZgpeWn14FgSRSpfUORfgiKF9CHS7l+wVx03nhKyqKCph5onekmh Z0Y945YqHrEnA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5302818006F for ; Wed, 20 Mar 2024 23:05:43 +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-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (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 ; Wed, 20 Mar 2024 23:05:42 +0000 (UTC) Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-221ce6cac3aso224589fac.2 for ; Wed, 20 Mar 2024 16:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710975921; x=1711580721; 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=zCNUaS6zQGSfF91X7Nqg1eqdd3jyoYT0BSQUnyNR6P0=; b=CBCRLjgvn7v2FXuQwq0wUXnaGyKbpyZQGzurBHxJ6hK2HMFcGyBE90sb39QuG5PLIK vRDS0+ui4L2E24nN02uxTRiqNSBxqfaIK9w4RUoo3J6hWvfHegd+hSZ+VquQTZIrELF8 od6oJMgIl8F1+3JVHmeNeE2uh7vMc3oxyNYnV7+Aq3vWfnSpf04RFjp5YzacwWwjcRkK XCKW6oneeU78g5xjGoTF/v8cqJEIO8N6Yzaw4DB+6r7FMdM1ylJdAzQhB985zW6mnhB+ UCiQqR9pcwHNDt2UsBtbodmXE4k47wzi+zwTSVC1Br/S8jKbAiS6/Serk6e6jiSNsNDp fJCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710975921; x=1711580721; 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=zCNUaS6zQGSfF91X7Nqg1eqdd3jyoYT0BSQUnyNR6P0=; b=IfrJaPBARvMCHUFh156SEGDhjLyRAPEvYicY/nxu2MJQhZKQEMY2BSjIi/uQbLPhiX Y7tV7EKiBmbotppb8giULU0WifRJ0aTKDXRz9FyJvX0bhaSIxSxygiCCMR2HlQUv6VEb qVftz9tejyHw5rbSyxgKP1ImUV1SK7z7I8PmokEZzBLMEDyosOXvLbrsSvPSVz3X30nD McsXePZjGwPOuiAPlkXx4mF3qJv9g7w3hmDee6YFX7mvfgB6MaemkbZcrhZXWt52pT1m 8w1fd851mYvNXT7WDWSL6Xd8Tk1vFEiHpAe6frUGi3UXvUOq9w4607hqCwp6nxW9YKiK x1iQ== X-Gm-Message-State: AOJu0YxVIO6b6Ruzcfx/yakzyAXL4ENT7GLhm876k/KEt+FKEBxcUPLG UYCN4DMsOPoSxstRpkf7J0VHFn52XrcAjqicxhShglgwG2+aFyYwO993uFbMfBsp9xdItg2V96Y g+GJOoG8N47uxukB0Zc5qAiSVZRJ5KiXUHS09qg== X-Google-Smtp-Source: AGHT+IGRIwBU2DHmD5KS2opwd1Q4b/GXAa8iLZvqDt2uJtCzf4QjXDni8gZRgiSZSCK5RsSiW3hoETEcuIv94wvMKo0= X-Received: by 2002:a05:6870:6589:b0:21f:d1e6:d8e1 with SMTP id fp9-20020a056870658900b0021fd1e6d8e1mr7700968oab.27.1710975920644; Wed, 20 Mar 2024 16:05:20 -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> In-Reply-To: <3F78A125-1946-42E2-A4F5-A2B282BE2107@rwec.co.uk> Date: Thu, 21 Mar 2024 00:05:07 +0100 Message-ID: Subject: Re: [PHP-DEV] Proposal: AS assertions To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Wed, Mar 20, 2024 at 8:30=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > > > On 20 March 2024 12:51:15 GMT, Robert Landers = wrote: > > >Oh and there isn't any difference between: > > > >$x as ?Type > > > >or > > > >$x as Type|null > > > I'm not sure if I've misunderstood your example, or you've misunderstood = mine. > > I'm saying that this should be an error, because the value is neither an = instance of Foo nor null: > > $a =3D 42; > $b =3D $a as Foo|null; > > Your earlier example implies that would make $b equal null, which feels w= rong to me, because it means it wouldn't match this: > > $a =3D 42; > $b =3D $a as Foo|Bar; > > If we want a short-hand for "set to null on error" that should be separat= e from the syntax for a nullable type. > > > Regards, > Rowan Tommins > [IMSoP] Interesting. I'm not sure there's a better way to say "set to null on error" since it would be barely sensical to give a nullable type on the right hand side anyway; so we might as well use it. In other words, I can't think of a case where you'd actually want a Type|null and you wouldn't have to check for null anyway. If you think about it, in this proposal, you could use it in a match: // $a is TypeA|TypeB|null match (true) { $a as ?TypeA =3D> 'a', $a as ?TypeB =3D> 'b', $a =3D=3D=3D null =3D> 'null', } No matter what, you're going to have to check for null if you want to handle all cases and throwing an error when you ask for a nullable type would render a ton of utility moot (i.e., this match statement wouldn't work). It's probably better to say, "I want what is on the right-hand side of `as` or an error." Including `null` in that type seems to be that you would get null if no other type matches, since any variable can be `null`. Robert Landers Software Engineer Utrecht NL