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>