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

From: Date: Mon, 11 Jul 2016 20:22:54 +0000
Subject: Re: Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-94480@lists.php.net to get a copy of this message
On 07/11/2016 11:30 AM, Rasmus Schultz wrote:
what's the actual added value of this sort of operator?
The only direct value to the language is brevity - mere convenience. But I think the biggest indirectly added value, is that this will discourage people from the chainable methods anti-pattern - so this has value to the community; those who write chainable methods can stop, and those who want chainable methods can get a wider choice of libraries that were previously too verbose in use for their taste.
As one of those proponents of chained methods / returning $this, I quite like this proposal. It neatly handles many (although not all) of the use cases for method chaining, specifically the most controversial ones, while not having any of the same potential issues. (Eg, when composing and delegating the method call to another object, you have to do some $this juggling.) It would not remove the need for all method chaining, but it would remove the need for the controversial ones that Rasmus is complaining about while letting people like me still write nicely compact and readable code. :-) (Modulo implementation details and debating the operator symbol for a few weeks, as per usual.) --Larry Garfield

« previous php.internals (#94480) next »