On Tue, Jul 12, 2016 at 6:36 PM, Rowan Collins <rowan.coll...@gmail.com> wrote:
> > Thinking about it, this becomes something more like a "with" keyword: > > with ( $counter ) { > count(); > count(); > count(); > count(); > } > > The semicolon suggests those lines are arbitrary statements, in which case it's ambiguous whether count() is a method or a normal function. And what if I want to call a function count() but $counter happens to have a count() method I didn't know about when writing the code? That's why I used a comma, to be clear the lines are *not* statements but rather only things that can go on the right of "->" (property access (assignment) or method call). The lines have their own definition, like the lines of an array literal do. I'm not sure if this is a good thing or not - with() statements exist in a > few languages, with varying degrees of acceptance. I don't remember seeing > one used as an expression like that before, though. > I'm only aware of the "with" statement in JavaScript, which is considered a real language wart because all it does is take an object and adds it to your scope chain, so that without knowing precisely what properties the object has, you can't predict what local variables are going to be masked and which ones aren't. There's a definite awkwardness of what to put on the left side of property > assignments too... > > with ( new Foo ) { var = 1 } > with ( new Foo ) { $var = 1 } > with ( new Foo ) { ->var = 1 } > > If the definition of the lines is "what can go right of ->" then it follows that the first line is correct, which also happens to be the most concise one :) . > > Overall, it's an interesting idea, but the details are fiddly, and the > gains marginal, IMO. > > I think the details are only fiddly if the lines can be arbitrary statements. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >