On Tue, Jul 12, 2016 at 2:30 AM, Rasmus Schultz <ras...@mindplay.dk> wrote:

>
> Would something like ->> be ambiguous as well? That's fairly close too
> - a double-headed arrow, not unlike the double dots of other
> languages...
>
>
A few weeks ago I proposed a syntax for setting multiple object properties
in an expression with the result as the object (
http://news.php.net/php.internals/93662). Both that feature and the cascade
operator can be considered instances of a broader need to manipulate an
object as an expression with the result being the object itself, and either
feature could support both calling a method and setting a property:

$this->setBlah(
    Blah::create(4)
        ->>foo = $foo
        ->>baz = ((new Baz())
            ->>markFixed()
            ->>label = "Hello"
        )
        ->>setBot(9)
);


$this->setBlah(
    Blah::create(4) {
        foo = $foo,
        baz = new Baz() {
            markFixed(),
            label = "Hello",
        },
        setBot(9),
    }
);


Would it be incohesive to have two different syntaxes for setting
properties and calling methods, like below?

$this->setBlah(
    Blah::create(4) {
        foo = $foo,
        baz = (new Baz())
            ->>markFixed()
            { label = "Hello" },
    }
    ->>setBot(9)
);


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.

Reply via email to