Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123795 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 B3CC91A009C for ; Mon, 24 Jun 2024 23:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719271344; bh=afLdc7aw9974ABOLPq43qCZOhjY2m6CbBzsamheUMx0=; h=References:In-Reply-To:From:Date:Subject:To:From; b=kczfUx31Hxp2W7okEHdrD/Zz7t0LnBua8kSxd87ndwMse6gIzBod09mJWntsCidrY iEhfnY2TF/LuRrjkYKjxNS+MkruCVgYh5SbgaXszobs1RI8JZOFPjxx67KEMzEiA2S VweXUnq+qJHmKr4pLVcDBvFBWsQzhAX+Gb6T08WE5QrffNIoBAgnBZTBJnNj3gEv8X vD3yb72T9N5A6iRoGXXakaXjaTKIr4h5J5HGojX+EZuOGhWsX4shryJD5xLiBPa2EU /zBLOas4sRzoFkLPNdrOLaFoBv7En83DEVqjqdJfvniUa+CxFt7R6mHmYckj4fmDsF LtkdhB21j4eIA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4C63180072 for ; Mon, 24 Jun 2024 23:22:19 +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-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 23:22:19 +0000 (UTC) Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6b50aeb2424so23897616d6.0 for ; Mon, 24 Jun 2024 16:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719271262; x=1719876062; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pUb+8OOCxOOQl8IT7rTYoqTZbiuJIj1O+ZkZ2ueMQYI=; b=gSXwKa1Zz/mQH7GsavaJLK3TzOXCtqIlnkLz5McXs1uOBInqoSRTOlAkIgTSTLt4HT 9NhsJJUmtFTsr+HcEwupCn31M82E+IgB/KEM+Tw4OGgPY8DCaWjmgkxX+0O4L/y2UjTc AWeiZUqmlcKy01tViSUyOmB7Fw+lHLtJlnBhkVi8tdAqVrfiLJQwb4aS8YqSpwh0ZDYY eVZnpVrny7YAeHWsSJIb9Ks7eUoe6u7sWYicmXCLJIirS/xp/lOagct75AgVyecafxI6 T7UbQJmHbBGO0RJHGUU/kbv0ssP+ZZYss6NblXQClDdxHMySIGXjWopp+gxC5l12Idkw y7nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719271262; x=1719876062; h=content-transfer-encoding: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=pUb+8OOCxOOQl8IT7rTYoqTZbiuJIj1O+ZkZ2ueMQYI=; b=a66NAM2eqt5G0J0bnVM9OXfgv/fSVRGUCI5ILk15bj8D30dVd6cFA8FCrjjhQw34d4 Ry3vltwKF8fsOGBTBznNl6hWe3BuSGRKqlTET/+k3jlEZK0Fbopd2rAQxYHrFMk7CZH9 mfpy/5lOCLJ41APRtA/h/3WnjKeoNhjfziB7gMdF9qM5/bFG5ZU8ZlACOQZTwX5tHjVY 6cVdsnyMSeWPtuTxVn3cZC7hVUzWfr8rc/YJCB4Xc6ref8qTihxEjVXS7PcUjFicSNtX jEYHbRDEr5Kx0WLfNMC11XySYTSkfHGv8HMf7PP7vZtEg2dM5nq5PkNolZWplhrv33C/ FaMA== X-Gm-Message-State: AOJu0YxmpuUrNzaoZLEVwu2Y4SeXBQtHapQl6slsLp8F3abrJm5gSlHd LJcwUqC3NDvgLAOERMPFpUBwoC1dAswRmGRDcvblste75u74GOunS7h+3PcaUESqFexv43nvLdu ZZNoyKpyR8zo3Rs9JHSxYw8TaOUzcIieIEAY= X-Google-Smtp-Source: AGHT+IGEYf+/yt3BTtrBqcr4L8AIlOxjOdmIRDhn0Uj0Jk6UORDobn5t90QyjQebrSoZoUlfWULU3DYdlskeOzNIKYk= X-Received: by 2002:a0c:e405:0:b0:6b0:74cf:6779 with SMTP id 6a1803df08f44-6b54099f8b7mr57133206d6.8.1719271261828; Mon, 24 Jun 2024 16:21:01 -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: Date: Tue, 25 Jun 2024 01:20:50 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) On Mon, Jun 24, 2024 at 9:54=E2=80=AFPM Robert Landers wrote: > > > The first means b is an optional key, but if it=E2=80=99s there, can on= ly be a string. The second says b is a required key, but it may be a string= or null. If there were a binding involved, that determines the type of the= binding in incompatible ways. I=E2=80=99m fine with requiring bindings to= be nullable for optional keys, but it strikes me as strictly less flexible= and not consistent with the rest of PHP=E2=80=99s behavior, at least not u= nder E_ALL. > > > > 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. This is just not accurate. Inexistent indexes are not null in PHP, they are undefined. PHP implicitly coerces undefined to null, because undefined is not a value accessible to users. The same occurs when accessing $undefinedVariable. For arrays, this fact is observable through `foreach`, warnings when accessing the index, and likely others. So yes, `[?'foo' =3D> string]` and `['foo' =3D> ?string]` are indeed different. The former accepts `[]`, while the latter accepts `['foo' =3D> 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? This is the same problem as `|`. Variable bindings within optional keys must be forbidden. I already mentioned that to Larry when we thought about this idea. Ilija