On 23/07/2016 12:15, Rasmus Schultz wrote:
I mean, maybe it's just me, because I'm familiar with the cascade operator
from other languages - but it seems simpler, more intuitive, easier to pick
up, and appears to solve most of the same problems? If so, perhaps it would
be right to consider the cascade operator as an alternative to this feature.
They're not really the same thing at all; in some ways they're actually
opposites. The cascade operator is a way of discarding the result of an
object-oriented expression, and reusing the same context repeatedly. The
pipe operator is a way of capturing the result of a procedural
expression, and passing it forward to the next expression.
It seems to me, the main difference between the pipe operator and a cascade
operator, is the anonymous context variable $$ created by the pipe operator
- I think, partially, this is what makes those expression hard to read; the
context changes (or does it?) along the way, but the (nameless) symbol used
to reference those objects, in the same expression, are identical.
Yes, the $$ means "result of last expression". In essence, it's a bit
like Perl's $_ variable, except that it doesn't exist outside the pipe
syntax. It has to exist to say where you're going to use that result in
the next expression.
In the cascade operator, you don't need a notation for it, because the
context is always on the left of the operator:
$foo
->>setBar(1) // context is $foo->...
->>setBar(2); // context is still $foo->...
But again, this isn't the primary difference between the operators; the
difference is that one is a way of discarding results, the other is a
way of carrying results forward.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php