On Wed, Jan 20, 2010 at 11:35 AM, Christian Grobmeier
<grobme...@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

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

Reply via email to