On Fri, Nov 26, 2010 at 9:46 PM, Peter Lind <peter.e.l...@gmail.com> wrote:

> On 26 November 2010 21:37, Ferenc Kovacs <i...@tyrael.hu> wrote:
> >
> >
> > On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind <peter.e.l...@gmail.com>
> wrote:
> >>
> >> 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.
> >>
> >
> > 1, I have to use a non-trivial library or "module" for a simple task, and
> I
> > don't want to write 20 line of code, and introduce 4 helper variable.
>
> If it's a one-off, then I really don't see the problem. If you're
> facing it again, write a facade.
>
> > 2. I want to get from point 1 to point 5 but I'm not interested in the
> steps
> > in-between (classical method chaining), but sadly one of the steps
> requires
> > object instantiation.
>
> If it's your code, then why are you not simplifying it? What's the
> point of writing code that you have to go through in five steps? Why
> not write a wrapper method?
>  The reasons presented sounds quite like "I want to be able write
> hacks easier" rather than "I want to fix an actual problem". I.e.
> there are solutions for this already that use OOP principles.
>
>
Sorry, I don't have the time and/or patience to fix every code out there,
which I might happen to come across in a project. :)



> That said, this fix may very well address other situations :)
>
> sure thing, I just told a(two) use-case from the top of my head.

Tyrael

Reply via email to