On 26 November 2010 20:36, Felipe Pena <felipe...@gmail.com> wrote:
> Hi all,
> I'm here again to presents another proposal, which adds support for
> instantiating a class and calling its methods and accessing its properties
> on same command.
>
> Example:
>
> <?php
>
> class bar {
>  public $x = 'PHP';
> }
>
> class foo extends bar {
>  public function bar() {
>    return $this;
>  }
> }
>
> var_dump(new foo()->bar()->x); // string(3) "PHP"
>
> ?>
>
> Other examples which describes the feature at
> http://wiki.php.net/rfc/instance-method-call
>
> Thoughts?

It seems fairly handy and I've been in situations where I wanted to do
something like that - in fact, I use factories to achieve something
similar.
 However, the more I use it, the more it feels like introducing code
smells into my code. You're essentially instantiating an object only
to immediately throw it away. That means you don't actually need the
object at all, you should probably be looking for static methods or
class properties. Trying to avoid statics by introducing a way to
instantiate and throw away objects in the same statement feels a lot
like reinventing OOP while adding overhead.

Anyway, just a personal observation. I generally favour the way that
PHP allows you to dig your own grave (i.e. I love the freedom of the
language), so as a developer I would probably favour this as well,
though I find it mainly a way to introduce hacks.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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

Reply via email to