Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126306 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 9FC2C1A00BC for ; Thu, 6 Feb 2025 10:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738838459; bh=XO9tY0tQnX4SNknJgyiBodlcFaWx1WPMZRKOadmgSVY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=e+kxV427rnNk/NH/S67OOKXJLiG2PSCXXdFfnKRNdx/HrXNBg/ibcBYD79cyvREUH qQtU/x3VJykxYy27kdG4vZJy20FKltuhU98WokjmgxYACaE86xyCkh+r8Kd1fH8UTj 7mGisA8TcGVVvdx0JPE2KNJvk2XZxT8X8ZnoKKNNYSK+pLU7IxuvpS+pJPGqKd2LLA wiFsXXcvPWkhtyfRmtCiVWp3RexLJWAbELpHQt3quojaj8gkI2h9q2YkqZyNOPQe+Y SiQGvc349PwhVmFHM0cPaYts9En9doBP7YFIvPIJ0AnRl/fzO4t6umR5/8QnLHNhST TzxpcQ658MKPQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2197A180079 for ; Thu, 6 Feb 2025 10:40:57 +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.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from gavin.smtp.mailx.hosts.net.nz (gavin.smtp.mailx.hosts.net.nz [43.245.52.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 6 Feb 2025 10:40:56 +0000 (UTC) Received: from 222-153-153-210-fibre.sparkbb.co.nz ([222.153.153.210] helo=[192.168.1.68]) by gavin.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1tfzMA-009M3k-2a for internals@lists.php.net; Thu, 06 Feb 2025 23:43:38 +1300 Message-ID: <934e9b43-ecfa-4ea6-910c-38bd581396f1@varteg.nz> Date: Thu, 6 Feb 2025 23:43:27 +1300 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Pattern matching details questions To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none From: Weedpacket@varteg.nz (Morgan) On 2025-02-04 17:31, Larry Garfield wrote: > > > However, there is a concern that it wouldn't be self-evident to PHP devs, and the variable binding side should have the extra marker. Ilija has suggested &, as that's what's used for references, which would result in: > > $b = '12'; > > if ($arr is ['a' => &$a, 'b' => $b]) { > print $a; > } > > There are two concerns with this approach. > > 1. The & could get confusing with an AND conjunction, eg, `$value is int & &$x` (which is how you would bind $value to $x iff it is an integer). > 2. In practice, binding is almost certainly going to be vastly more common than pinning, so it should likely have the shorter syntax. > There is already something analogous, in the sense of "binding to someone else's variable" in named parameters. Running with that analogy gives: $b = '12'; if ($arr is ['a' => a:, 'b' => $b]) { print $a; }