(Replying to a few of you in one go, I hope the formatting is clear)
>>> we have changed the RFC to use => instead. So the new syntax is
>>>
>>> using (new CM() => $cVar) {
>>> // Do stuff here.
>>> }
>>>
>>
>> Going to be controversial here, but this is confusing, because it operates
>> in the exact opposite of every other usage of => we have.
>
> I agree with Matthew.
>
> I think it makes more sense to reverse them, like this:
>
> using ($cVar => new CM()) {
> // Do stuff here.
> }
It took me a long time to figure out what you were both saying here, because to
me the direction of the arrow seems to consistently indicate data flow: you
call the function, and data comes out; you enter the context, and a variable
comes out.
But I think I see it now: you're treating the context variable like an array
key, that is somehow "bound to" the result. Except that's not what's happening,
otherwise we could just use "=".
>I also agree with Matthew but the reversed proposed here looks very very
>awkward to me. I think the most natural thing is the “as” but I may have
>missed the discussion on why it had to be changed.
>
>Thinking of foreach ($array as $value), an item from the array (left) is
>assigned to $value (right).
This is the way to read the "as" syntax, yes; as I've said in a few places, a
Context Manager is like an iterator that goes around once.
> That seems symmetrical to using (new Manager as
>$manager) where the instance (left) is assigned to the variable (right).
This, however, is why it was changed: that is *not* what is happening. The
Context Manager is not assigned to the variable, it *produces a value* which is
assigned to the variable.
Again, look at the foreach equivalence: you wouldn't write "foreach(new
MyIterator as $iterator)", because it's not the iterator that ends up in the
variable, it's the *items produced by* the iterator.
So you have "foreach(new MyIterator as $item)" and "using(new MyContextManager
as $contextVar)".
But evidently that is not obvious to readers.
My favourite among my own suggestions was "using($cValue from new CM())", but
Larry didn't like the reversed order. I also suggested 'using(new CM() for
$cValue)", but I don't think that's as clear.
Perhaps there is some other word we can use? I suspect it would not need to be
fully reserved, as it's used in a very restricted context.
Or, perhaps there's something other than "using" that clues the reader into
"this object will be used to produce an arbitrary value" in the same way as
"foreach...as" does?
Rowan Tommins
[IMSoP]