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

From: Date: Tue, 12 Jul 2016 15:32:40 +0000
Subject: Re: Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-94491@lists.php.net to get a copy of this message
On 12/07/2016 14:54, Michael Morris wrote:
Agreed, but what about static methods? Triple colon perhaps? A::setFoo(1) :::setBar(2) :::setBaz(3);
This is a rather different feature, because you can't really express that as an expression returning something. What is $result set to if I run "$result = A:::setFoo(1)"? Or, equivalently, what is the value of the chain you've written? (Presumably, the "::" on the first line should be a ":::", otherwise I'm even less sure how to read it...) I think saying "if you want the cascade operator, you have to use an instance, not static methods" is reasonable enough. Especially with the perennial discussion about namespaced functions being better than classes with lots of static methods (if only we had function autoloading, etc, etc). Somebody quoted a concise explanation of the cascade operator earlier, which bears repeating, in PHP context: // Proposed $result = $foo->>bar(); // Valid in PHP 7 $result = ( function($subject){ $subject->bar(); return $subject; } )( $foo ); // Long-hand $foo->bar(); // discard return result $result = $foo; There's no magic needed to create longer chains, or combine this with other operators; it's not a transform done to the source code, just a normal expression. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#94491) next »