Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123898 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 AB3421A009C for ; Wed, 26 Jun 2024 21:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719438250; bh=Wvg2TTApcad+50wRtYSIC2dC3T/WwfQhpvZr5etvt34=; h=References:In-Reply-To:From:Date:Subject:To:From; b=RT1x9mH56/kAnJTa812B69ECwqlqmx/spryB7+6aZ3M1VUJBrxBfpLCTgOMI2z071 K4ISwaHi2g+cNH/6U20KsTF+yKQdsiXiGW4sn80mqCJVp+Q5IlfTzyA5/CuBOMQlJE zzuNHI5wH1V8KFylhGUSiP9y1vCXj+QX+SBpP0AEYRP77IoYKefUxWQv8lpYY8V6q2 B0ywXa3DrVbsVEMppiOXr5UvGmVXG2ypnu8+O+7yyvVv8m7qUdfrlauIQoEucM9e1P TUAobyinB/znG2WycIEYolz6ZRQsj30T8C8mTnyQAcHcVFZ2C/hR4h/lIl5ow5yKs+ teLXWxqfNL8SQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C6A6180817 for ; Wed, 26 Jun 2024 21:44:09 +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-f43.google.com (mail-qv1-f43.google.com [209.85.219.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, 26 Jun 2024 21:44:08 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6b50a68b0b3so8839496d6.0 for ; Wed, 26 Jun 2024 14:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719438170; x=1720042970; 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=bzYwKBODiot6UyPOGZB8lakKw1G2qc/ljyVwRsM++r4=; b=Gyjn5Tv/eDVQwRB/sSP9fDo1SPKUyc2BvMdoOWriE5Oe4iySUzYQK+qwya5cxnJN3+ 4g5kTuDXy4ReLCZ3kHJOH5qnmPnsFVkaARKUJklSxwrILyG7dBww14aTgXiAQ4/PN8s4 k7djwYeKvfquHIxRbyxykGNRnZj4gWQ+EdUOuXNHG06IUNEFJU9qVcOoDLifTEnLAfwc zjAyRuI0uAO8QWUqW2KaPQko3MGad5TZTuFHYCdlOs3wBwkemPMW2vroUPO4k/1LQP+D m75yEUNhKGCcIEgNaPQOzf1yRdAW3WG6ZgRxiIKa7AnLIL8A7xFiFxnWAv17PkSIAoQI hrWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719438170; x=1720042970; 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=bzYwKBODiot6UyPOGZB8lakKw1G2qc/ljyVwRsM++r4=; b=eGefc4KCU9XCKxz3q0Fs6kYyXJZ2EcfA9BVmMIGUF4FfGJgcHXXgiA1/uBQSEmeYUV GJ0WIPNZgCL4zihZHpDXcz2kyTJBGeL9CBaEhCOq9SfM45ss8vBavMbV38p0Peww5ih+ 3+1fRu7R6ArSL0ETW6SP6y6RbXiPFG2AZdzESPjX/pDas2aqa9LDS829jZkSBrsEDBV1 5MjDpCb70NKqRnUwkJF7SYz9xHhci24zu2Op2seTrb325f/HV8gaReDa+Y77AVLyMCsg 0eZZW2Vn78fsJIskAgQEjDY7G+Hu3+Lc+zSMwO+JoeSDEY8CnvYu7YBomm1IbA5Yrloq 7pNQ== X-Gm-Message-State: AOJu0YyMUWvauKclz3Zv98KFVa0nnEyErydRWutvbRGPNf4x+BuuC1BH PraAVu63O/qwQRqSs+Z9Ah1U9L5aFXoq4JrcpmkPPMXRJq/Ba2mVN9ovJxJQMT7ml/DMb7Rq4dV nTULddFYWg+b9JOrdZNeja9aqM8uwRpHpY9o= X-Google-Smtp-Source: AGHT+IGZ8vOqGk3wcHdQP6AXDubQZkUhBqtVf6w0EontAy5GF3bW39MtI/BsRkJZhCaaPecLe3LjMxM18ZMRh078jyo= X-Received: by 2002:a0c:f8c6:0:b0:6b5:81ac:6b84 with SMTP id 6a1803df08f44-6b581ac6ed1mr25490076d6.14.1719438170313; Wed, 26 Jun 2024 14:42:50 -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> <97a93ae2-5202-47eb-bf51-ec1e976ea765@app.fastmail.com> <78D0FFF7-3867-4D71-B0C0-FA23E5121C39@rwec.co.uk> <10390963-0c2c-441a-bcce-20a0433948c5@app.fastmail.com> <8498ecf7-f431-4d68-aaf1-dc4cfb00241b@app.fastmail.com> In-Reply-To: <8498ecf7-f431-4d68-aaf1-dc4cfb00241b@app.fastmail.com> Date: Wed, 26 Jun 2024 23:42:39 +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) Hi Rob On Wed, Jun 26, 2024 at 10:36=E2=80=AFPM Rob Landers wr= ote: > >> On Wed, Jun 26, 2024, at 21:50, Morgan wrote: >> >> So the issue has nothing to do with this hypothetical infinity of >> unobservable nulls, and comes entirely down to the fact that with this >> pattern a variable may pass >> a) because it does not have a key named 'foo', or >> b) because it has a key named 'foo' with a string value. >> >> In other words, "this key is optional, but if it is defined it must > match this pattern". > > Seriously, write out using it both ways. I asked in the beginning for som= eone to give a realistic example showing a practical difference in the fina= l implementation and I haven=E2=80=99t seen one. I will gracefully eat my h= at. The main issue is that key-existence-check is logically inconsistent wi= th itself (if you say the key shouldn=E2=80=99t exist or be a string, you= =E2=80=99d be surprised to get null from that key!) function test($value) { if ($value is ['foo' =3D> ?string]) { $foo =3D $value['foo']; } } test([]); With your approach, the example above would emit a warning, even though the context within test() doesn't look like it should. If ?string means that the index might or might not exist, all code that accesses them must check for existence, even when not needing to handle null itself. That doesn't seem desirable to me. I also think the issue goes further. If anything|null means that the offset might not exist, does that include mixed? That makes ['foo' =3D> mixed] essentially useless. Ilija