Re: Re: function call chaining
| From: | Christian Grobmeier | Date: | Wed, 20 Jan 2010 12:05:14 +0000 |
| Subject: | Re: Re: function call chaining | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46836@lists.php.net to get a copy of this message | ||
On Wed, Jan 20, 2010 at 11:35 AM, Christian Grobmeier
<grobmeier@gmail.com> wrote:
>>> Why would this imply "dropping" the object?
>>>
>>> This:
>>> $foo = (new bar())->someSetter();
>>> Looks a lot better than this
>>> $foo = new bar();
>>> $foo->someSetter();
>>
>> The second version is much clearer. You know exactly what $foo is. In
>> the shortened version you have no idea what $foo is without reading the
>> code for the someSetter() method. On first glance I would assume that
>> $foo would be the success/failure return of the setter and that the
>> object is dropped.
I also think that:
$foo = (new bar())->someSetter();
is assigning the return value of the setter to $foo. I would love to
have a language feature like anonymous classes, but if $foo contains
the bar-object after this line - wow, how would I hate this. From my
understanding both examples should act differently.
Rephrased: if one would say, the constructor returns itself as a
object, you could call the someSetter() method on the returned object.
The return value of someSetter() is then assigned.
Having such a language feature could help with having that later:
$a = new AbstractClass {
public function methodToOverride() {
// overriding code
}
}
i think this already works:
$a = new MyObject();
$a->setListener( new MyListener() );
but this could then work too
$a = new MyObject();
$a->setListener( new MyFactory()->createZipCreator() );
As said, I would love such a syntax feature
cheers
Christian