Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123786 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 BFE6B1A009C for ; Mon, 24 Jun 2024 19:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719258915; bh=KUhkYwAstoYXMLcKIlGPr8PnHbJt3MQPAEGLUmUyGdo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=M31aRt3zovM3xsfobgG0pjTU3TTAh8qBPh5QBZ9G4S6wEl2D8W5NEw3UCqH5FVilR a/TNz0+j+snZUCyiKjoJwNHEDQnVahhxfNd8sNi6Qme5phgmeWad5MDE9UuO1MxFE9 e0yD9uFzxLrW6PStMwExJjvmBtdTNYmEk4tMaAXtIqhTd93PyiMS/uNozBJwqkIoh7 moZUUKgpjqBWdc/70r99aZ/bMhfiRNK+mZrPNzqB3wd+HXsaCiHI0PhKxRFA5DjmIo HH4Ss4otp3dczgdQTIs6QBxl/9yysEHgmhclOVfJhqUz4NDqFTqB3K9dVGfna5IlLT TZHXlEHpTX24g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E151A180072 for ; Mon, 24 Jun 2024 19:55:14 +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_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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, 24 Jun 2024 19:55:14 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ec10324791so57917661fa.1 for ; Mon, 24 Jun 2024 12:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719258836; x=1719863636; 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=vJj5+0188VU+xiA9+GE/rKxMAfC/Hy89LxP6Z3rfW5c=; b=i6g7wPRBSPUYE8Xuh/xAnxMeLvKAvbFAq1lRBbMfb9VBp42KNAZQMo4yYtVlCgHbDm Mi1azR9IFx2pJQEDKcfVjaHpNoi1Ewe5cH1GgyrZYX3pagZNSxYX/cc3t0HTrUpoB6zD aOX3huTwxUZ7o254ZZkPOA6sgZyTHWs/BT46JvRtpQzvy8qID/e6F73o8WpgpABqRnpD 1D2H2lkDygV0/X4EyCTbvbdplSHdGTyokVYl4L3rhSIN5bYqHhRib1+Gn5GHxPpFmC5P 043FSfUKRg/aKt3rzXuJrT1AJoIYpy4liBt47bIGseOMdumpvfHnxTqmPq1vBsJOHHzl EVZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719258836; x=1719863636; 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=vJj5+0188VU+xiA9+GE/rKxMAfC/Hy89LxP6Z3rfW5c=; b=dtMsn7x2cadSRQz/HQrM+h1eO7N+p3aL4arM7MrGFHz2TKf1liBWqLUOb8J6lew3pj oTW29IWRTjoBTnWxAzFm/cU+Ph6FXE/8cynfScf1bMQVPX25v6bu9H9FlUrgRvmXKDqA dtpQ1ghVEOKNXcVYP+vF5XMWgPUNO4WMjP0sNjUxq02LkCCCIFJGVTn+9jF10a0W1sVt vyc9NDvNF/xyZKNWkvSxg+/JxPW2Qz9RMsuWwYnwag484Xf1hGTM2jH0ZOneFTrj/Dxq MugDgDxDg1gZolMDZm8EdMi5apFR8ZVeo7wQLGJxY/mwJCt0BF+pVU0bWLkcwobRtxAZ OeHA== X-Gm-Message-State: AOJu0YzmhRLrPfuW9QBbPZChawocMx+XlHAl/op41bSdJnuQph+hjD2f GzGJBbShz0l1lWdNX3nbhJpCpVE6WstfrSyjyDJ9j/0GaO4KFNBqfpU3lUplg22liprD9PsPbGw w+PGnsm2mcy7HtzrhhJFVHw7UVhQbAXy6BPc= X-Google-Smtp-Source: AGHT+IF0erzMcz7fhRifmP6TEpzmcynGQxCt4CtYze4G6tE6+q+Pkot1k76WqZV+Z6tTk1WWxDdQSuFdpRzL+H18eB8= X-Received: by 2002:a2e:95ca:0:b0:2ec:5200:a941 with SMTP id 38308e7fff4ca-2ec5b2dd968mr33484611fa.38.1719258835986; Mon, 24 Jun 2024 12:53:55 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <1E295280-619B-4490-B53C-0899B64F9215@chaz.works> In-Reply-To: <1E295280-619B-4490-B53C-0899B64F9215@chaz.works> Date: Mon, 24 Jun 2024 21:53:43 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: chaz@chaz.works Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Mon, Jun 24, 2024 at 7:28=E2=80=AFPM Chuck Adams wrote= : > > > > On Jun 24, 2024, at 3:31=E2=80=AFAM, Robert Landers wrote: > > > > > > There's no need to use `?` to check for existence on a key, so this: > > > > $arr is ['a' =3D> string, ?'b' =3D> string, ...]; > > > > should be this: > > > > $arr is ['a' =3D> string, 'b' =3D> ?string, ...]; > > > > because $arr['non-existent-key'] is NULL. > > > > > The first means b is an optional key, but if it=E2=80=99s there, can only= be a string. The second says b is a required key, but it may be a string o= r null. If there were a binding involved, that determines the type of the b= inding in incompatible ways. I=E2=80=99m fine with requiring bindings to b= e nullable for optional keys, but it strikes me as strictly less flexible a= nd not consistent with the rest of PHP=E2=80=99s behavior, at least not und= er E_ALL. > Hi Chuck, To be honest, this is one of the smaller concerns I have with the new syntax. There might be some misunderstanding here, though. A non-existent key is NULL, always has been, and always will be. No current RFCs are stating otherwise, to my knowledge. While a warning is emitted when accessing a non-existent key, and some people trigger exceptions or fatal errors on warnings, this isn=E2=80=99t universal, and i= t isn=E2=80=99t always an error (after all, the value is NULL, which might be= a properly handled case). If you see the warning, it=E2=80=99s usually a hint that something might be wrong, but often, a quick ?? is all you need to make the warning go away, further reinforcing that the value of a non-existent key is NULL. $arr =3D ['a' =3D> 'a string']; $arr is ['a' =3D> string, ?'b' =3D> $value, ...]; This syntax implies that a non-existent key is a special case, and if it passes as-is, it will be. If there is a binding and the key is missing, what happens to that binding? Is it left in an undefined state or is it assigned NULL? If it is assigned NULL, what is the value of checking for non-existence; why not just check for NULL in the value? If it is left "undefined", then you still have to handle it as though it is a NULL value (perhaps more so because simply trying to detect its value may cause the very warning you are trying to avoid -- and will fatally error in PHP 9: https://3v4l.org/Rbadk. see https://wiki.php.net/rfc/undefined_variable_error_promotion). Thus, this "key existence check" is inconsistent with the language and possibly redundant, as you'd have to check that resulting value was null anyway: $arr is ['a' =3D> string, 'b' =3D> ?string, ...]; Hope that clarifies things.