Re: Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return)

From: Date: Tue, 12 Jul 2016 08:36:53 +0000
Subject: Re: Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-94486@lists.php.net to get a copy of this message
On 12/07/2016 00:14, Jesse Schalken wrote:
If so, some consideration should be made as to which syntax is preferred to solve this problem generally for both setting properties and calling methods. I prefer the "obj { .. }" syntax because it mirrors object literals in JSON/JavaScript, object initializers in C# and C/C++ and Haskell record syntax, is particularly concise when nested to create large trees of objects, and avoids the noise of "->>" on each line.
All the examples you've given for that syntax are for initialisation, and I'm not sure how readable it would be for the general "do several things in a row" case: $counter { count(), count(), count(), count() } Thinking about it, this becomes something more like a "with" keyword: with ( $counter ) { count(); count(); count(); count(); } If with(){} could be used as an expression, you'd get something remarkably close to your initialiser example: $this->setBlah(
    with ( Blah::create(4) ) {
            foo = $foo;
            baz = with ( new Baz() ) {
                markFixed();
                label = "Hello";
            };
            setBot(9);
    }
); 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. 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 } Overall, it's an interesting idea, but the details are fiddly, and the gains marginal, IMO. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#94486) next »