2013/2/26 Lazare Inepologlou <linep...@gmail.com> > Hello Nikita, > > 2013/2/25 Nikita Popov <nikita....@gmail.com> > > > 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())"? > > > > > > I'd like to extend this support to any expression instead of just new. > > > > Why should be do this? Because it's just an arbitrary restriction. > Removing > > it would for example allow clone calls in the parens, so you could do > > something like (clone $date)->modify('...'). Which - you may have already > > noticed this - is more or less a replacement for the DateTimeImmutable > > class that was added for 5.5 (with the nice benefit of being fully > > compatible and not being an object oriented abomination :) That's just > one > > example, but I think there are a lot more (especially if you also > consider > > that it allows array dereferencing too). One further use that is of > > interest to me personally is for https://github.com/nikic/scalar_objects > , > > so I can do calls like ("foo")->bar(). > > > > A nice side benefit from this is that it removes a shift/reduce conflict > > from the parser. > > > > The patch for the change can be found here: > > https://github.com/php/php-src/pull/291/files. It's a very simple patch, > > it > > basically just changes one parser rule and adjusts the allowed opp types > > for some opcodes. The rest is just the vm regeneration for the new op > > types. > > > > I hope that this change is trivial enough to not require dragging it > > through the whole RFC process. If there are no objections I'd commit it > > sometime soon. > > > > Thoughts? > > Nikita > > > > > Lazare INEPOLOGLOU > Ingénieur Logiciel > -- github.com/KingCrunch