Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122698 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 B9E9F1AD8F6 for ; Wed, 20 Mar 2024 12:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710938915; bh=9yPKlrdiN7Met2yr4ukjq83SLjTvs+pHpSx4sTsnax8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=G26z3vYi1jM4Id8Y8WOW9vNwvvbFHl3LGzp+3tpVW2fC0/7jFU2tkrKxRTzOSiC1d uD4T+mcjJYwmDDsKl12Zbi4o4GQ9Syg1LWEOYrY7YZqBHuj17ixXbS9MluVFHK7Y7X JLYu3hHoU9J9C0o22Q2x7/3QU2Dcj1ybsCIuHTiRh/zlvZ3OSQKhx9n1rPS4MvOIu3 t9J3WXaAwH6eiFkoxBr6tSV385DrA895NophLRftFTWoML0/RAQz2gpsYupBwOC9w4 TYUW5GDcDg49dp1vbkCih3o4gVGr9mVYPonCk9iIKrJsjVhpg69HuFGjItUH7gdQ2W AUlTTBvCh+KyQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 23E1C18004F for ; Wed, 20 Mar 2024 12:48:34 +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-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (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 12:48:33 +0000 (UTC) Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5a46ec4050eso3583032eaf.2 for ; Wed, 20 Mar 2024 05:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710938892; x=1711543692; 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=9yPKlrdiN7Met2yr4ukjq83SLjTvs+pHpSx4sTsnax8=; b=TF3hkga7rM4XW/oZ1t22MzPGzgMCR97T+icF2Q/ZMO3YSR6v4d3Q+D39V2OneknttN ZTfZn5uFeqDG8UNJmFF2MTUvX50B1Wb69GjF5+ICcOuw4YYPZlyPAuTtpPdYi5EGmfWU 5qMC6Aus2G+YLXOqw1CXkLZ13QGth6ESk4vNufaywX6WDXlz+UtA2L7eiBG8hkYAlgoE dyZJvE25N7iQH5wDlpgoJZxbLHbFL1NMpGV86oe4ap0nm42P3QquUmMMw5BXJoigNEvz kjkoKXbPv91o1tyBlYkk/iVZkczKe0/2BzZaG9JLuXG6wEj2DUCWe5BFRNmAJX73x8Bz Ahng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710938892; x=1711543692; 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=9yPKlrdiN7Met2yr4ukjq83SLjTvs+pHpSx4sTsnax8=; b=RJyBoUi/PFqCKiIQcHALLpX9XYfhqDluhhwdfsyCkBLKvObyE5cgJr4ErBTPWQp+yR iLN6f9Sd91lmvVfhxHEcF1+NUs7gdwlMu2iHOrUnzXKA69PMrSvlAYSYTRNAWmNbXK3z 7k6/2qEMO/uccC8CD4Z/Xm3Slhojfvky4h6P+xr8kMmMmIu+O4435P4geutIZjiCcCPE 10hWs2fDfKsc4mJ+M+JFLyBDxBQibHaEzmWOsSA58truKmXRjK8V1UkJOxSa19yIrxyL NiT9Bevv2J8NYfMLLIcTZB+i+UCrDS5Dl76z+VpkzSmk92PQw5WD7XQtXF4XyKicSuXs ebgw== X-Gm-Message-State: AOJu0YzbhqbSU6SGE8kllOcPGjzgPatZI7nwXAs+tWjfizqjF25rLxFk F5Jn+8CVlEffFnYLNCFyFqVJtAm7F6jqQII2ikK7ZVmp71Jqq32hJGqOkrB3IjyE1XeceOOLeNn j3zSWWtQYfVGukoWkmOv+Dx7Ld4XL1qyggIhz0Q== X-Google-Smtp-Source: AGHT+IFlQcbq9OISmYrA2O1NwIjFeh1Cn4L8hOoUR4PXpB/338vMPZNa4nKOxmx2k4h5PhpcPzicTbDcz/XsqR2+LfA= X-Received: by 2002:a4a:6f56:0:b0:5a1:1cf8:cdd2 with SMTP id i22-20020a4a6f56000000b005a11cf8cdd2mr15672175oof.6.1710938891911; Wed, 20 Mar 2024 05:48:11 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 20 Mar 2024 13:47:59 +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 Tue, Mar 19, 2024 at 10:06=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 19/03/2024 16:24, Robert Landers wrote: > > $x =3D $attributeReflection->newInstance() as ?MyAttribute; > if ($x =3D=3D=3D null) // do something since the attribute isn't MyAttrib= ute > > > I think reusing nullability for this would be a mistake - ideally, the ri= ght-hand side should allow any type, so "$foo as ?Foo" should mean the same= as "$foo as Foo|null". > > > A better alternative might be to specify a default when the type didn't m= atch: > > $x =3D $attributeReflection->newInstance() as ?MyAttribute else null; > if ($x =3D=3D=3D null) // do something since the attribute isn't MyAttrib= ute At that point, you are just reinventing already existing things. If you wanted to do something like that with my proposal: $x =3D $attributeReflection->newInstance() as ?MyAttribute ?? MyAttribute::createDefault(); Robert Landers Software Engineer Utrecht NL