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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to