On Thu, 5 Nov 2026 at 19:33, Larry Garfield <[email protected]> wrote:

> On Thu, Nov 5, 2026, at 12:18 PM, Stephen Reay wrote:
>
> >
> > Hi Larry,
> >
> > TLDR: why `=>` rather than `as`?
> >
> > As a userland developer I like what this is trying to achieve. I'm not
> > knowledgeable enough about the internals to comment on the finer
> > details or their ramifications - I just have a bike shedding
> > suggestion/question which seemed glaring to me so I wonder if it's
> > because of an ambiguous syntax or some other issue?
> >
> > The `=>` symbol seems odd to me, given how it's used elsewhere
> > (generally as an indicator of a key/value pair, whether in an array or
> > match block) and how generators/iterables are used elsewhere (ie
> > foreach as)
> >
> > Your example is:
> >
> > using (file_for_write('file.txt') => $fp) {
> >
> > Whereas to my eye this seems like a much more obvious choice:
> >
> > using (file_for_write('file.txt') as $fp) {
> >
> > Anyway, just a thought.
>
> The v1 RFC originally used `as`, which is what Python uses as well.
> However, a lot of people were concerned that it implied that the left side
> expression would be "used as" the right side variable.  While in some cases
> it might be, the typical case is that it's not.  The context variable is
> emitted by the context manager, but is not the same thing.
>
> At the time, no one could really agree on a better keyword.  But => was
> right there waiting to be used, and already has an "evaluates to" or
> "yields" or "produces" meaning, which is roughly accurate to what happens
> here.
>
> I don't mind `as`, personally, but the consensus before seemed to not care
> for it.
>
> --Larry Garfield
>


Hello Larry,

Using the `=>` operator for this case looks inconsistent to me as well. In
my perception, the meaning of `=>` in PHP is that of mapping as a function
in the mathematical sense: the domain mapped to the image. For example, we
have keys mapped to values in arrays or in `yield` generators or even in
iterations with `foreach`. Similarly, the usage of `=>` in lambda functions
is also consistent as we have a mapping of input to output.

In this new case, however, it looks like it is used more as an assignment.
In the statement `foreach ($iterable as $key => $value)`, the assignment
operator is `as`, while `=>` consistently carries the meaning of a map. So,
I would argue that using `as` for assigning is more consistent with the
previous syntax choices.


Lazare INEPOLOGLOU
Architecte Logiciel

Reply via email to