Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122699 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 300571AD8F6 for ; Wed, 20 Mar 2024 12:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710939113; bh=oznYlqBkQ2yFJSEevUrkhvzamazBrnnDaFNKLTcD1/4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XVJYyzy+eLwU8H9MWaExMAPxEJg6dNnHCkfk6WiO87kgJ9plfk/pxXV8KjFjoYUNP KWsgD2ccgeEn6FAOuNPa8ClFgp8CZTv0sZTGfrmyNTwTsfcR5iLaHxZF7VsrUUKeru TSUMgjyW+QymcCTa6ghSvxsWj3tnY59nzejIyc/0bIIisqX1HMHz1r7ZPEPuUsAg5T fYWk7iO3wDoGI9+li2ATinipSlugq/QiDTUf39rugQhc1a/g12nrpC+FSEARBdqhU8 I1hwFy4s+khHh8tW8iSzdA0GiSPez+ltqNGVHY1JmVBiTLxC96rNq7XwgqFc7HCAbg NXDFG4k1Wp6MA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F78018064F for ; Wed, 20 Mar 2024 12:51:52 +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-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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:51:49 +0000 (UTC) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5a477c48fdeso3378410eaf.2 for ; Wed, 20 Mar 2024 05:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710939088; x=1711543888; 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=oznYlqBkQ2yFJSEevUrkhvzamazBrnnDaFNKLTcD1/4=; b=C3pQYwDl7WlrIN0Gnw0SHI3D8w1ynNkycE26NUzF9EZMg5/Hcsr1KayUz+KyZ9sZ/P GDblo2h8eCgPc3Brd6F4kifvUGiRcwa3PTa3IpE/2X43ZDysZr6J0V0frYCMI3YodV60 CvtMWF1YIaGMbz5ADpx1Zq20tCwWQLoCti2opUaxHoBFVbS6gcZBaVDU1KxY3s291Wxg 7PlRa8YabT1xy6la0e+hP84jT4LAQgjSTfVu9M2nYF9jFm/JoiZL+gGADImI2ba1jSoc rf3U7c0TZq09o01NMrOxKI8EmKSQOpdwjt6YG6hwMBl6maAGWZE3lOO/Kbn2wNmpgSeP hi+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710939088; x=1711543888; 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=oznYlqBkQ2yFJSEevUrkhvzamazBrnnDaFNKLTcD1/4=; b=DNVYWe5IxWMbRn3sVpWxBfkv3WIkHyFlgqVgNAEscblAlv/XYsCo8yzSI+thwXZH0z t674JQNdJDfeYh8lknTh0vPxGV7/s4v62CgYvyWf9gVYrUXobsHT+LJ00w8CWJva+v4k 05Xoi0KhUePSfZQGPOT/KHPwFvksXIekW4yoRMSV7LNhEMO0uPO3H2RjW9Hn3x0f7sHs ZAl/glR4kP/oSNfs1+8bTf9BaB4MQKXjOjjr4xMxmX3ToRGF5Rze5w2XAYj+pTQaypKW 2FT7qE9bCZIGfmBGENAhl+V9m4ygF4tB5qGi1tXXeJsx8j59fFDYKOOCh5tSo0esoThm 1gWg== X-Gm-Message-State: AOJu0YxigwlYT2WdR8S9Z9cnL1EpixhxGw0YS5iH/7FmQZGWL1sfzhfp UXLgBKx+qwPQUHbb+4FUcD81UnERUqnEzYV/27Dm9wfFhLi3XzXjafUUuDHdv0HVqWiLJ7vzmtT yqyZt1YsiHPM1OOllEIg+3RQXdtwHHS27M1A= X-Google-Smtp-Source: AGHT+IFsvg0iON4DudeMLIemsVFFheMLsXXWh5keeQlAGiP9jYFLJpkGxU6f1MmsJNJr3LYtExR8DCyyfOtyn05lMLU= X-Received: by 2002:a05:6820:1629:b0:5a1:78c0:4327 with SMTP id bb41-20020a056820162900b005a178c04327mr17599085oob.4.1710939087784; Wed, 20 Mar 2024 05:51:27 -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:51:15 +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 1:47=E2=80=AFPM Robert Landers wrote: > > 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 MyAttr= ibute > > > > > > I think reusing nullability for this would be a mistake - ideally, the = right-hand side should allow any type, so "$foo as ?Foo" should mean the sa= me as "$foo as Foo|null". > > > > > > A better alternative might be to specify a default when the type didn't= match: > > > > $x =3D $attributeReflection->newInstance() as ?MyAttribute else null; > > if ($x =3D=3D=3D null) // do something since the attribute isn't MyAttr= ibute > > 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 Oh and there isn't any difference between: $x as ?Type or $x as Type|null The codebase I work with prefers ? over |null, but they are the same.