Re: Pattern matching details questions
| From: | Morgan | Date: | Thu, 06 Feb 2025 10:43:27 +0000 |
| Subject: | Re: Pattern matching details questions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126306@lists.php.net to get a copy of this message | ||
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]) {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;} 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.
print $a;}