Re: Allow (...)->foo() expressions not only for `new`

From: Date: Tue, 26 Feb 2013 12:58:05 +0000
Subject: Re: Allow (...)->foo() expressions not only for `new`
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Tue, Feb 26, 2013 at 01:35:47PM +0100, Sebastian Krebs wrote:
> 2013/2/26 Lazare Inepologlou <[email protected]>
> 
> > Hello Nikita,
> >
> > 2013/2/25 Nikita Popov <[email protected]>
> >
> > > Hi internals!
> > >
> > > PHP 5.4 added support for expressions of the kind (new Foo)->bar(), (new
> > > Foo)->bar and (new Foo)['bar'].
> > >
> > >
> > I guess it must have been discussed, but Is there any technical reason or
> > conflict that prevents us from having something like new Foo->bar(),
> > without the extra parenthesis?
> >
> 
> It could mean "new (Foo->bar())", which in this case is invalid, but there
> are other cases, where this problem is more obvious
> 
> if ($foo) {
>   $bar = 'Classname';
> } else {
>   $bar = new BarClass;
> }
> 
> new $bar->baz(); // "(new $bar)->baz()" or "new ($bar->baz())"?

The precedence is quite clear, it would be the first, see:

    http://www.php.net/manual/en/language.operators.precedence.php

However, I do agree that it might be a bit confusing.

What is disappointing is that I cannot go:

    ($f = new Foo)->bar();

That does not suffer from a lack of clarity on intent.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>


Thread (32 messages)

« previous php.internals (#66242) next »