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

From: Date: Mon, 25 Feb 2013 16:20:01 +0000
Subject: Re: Allow (...)->foo() expressions not only for `new`
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-66199@lists.php.net to get a copy of this message
It makes sense to me. +1 for making the syntax more consistent and natural. - Jon On Mon, Feb 25, 2013 at 10:14 AM, Nikita Popov <nikita.ppv@gmail.com> wrote: > Hi internals! > > PHP 5.4 added support for expressions of the kind (new Foo)->bar(), (new > Foo)->bar and (new Foo)['bar']. > > 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 aÉ»o > ¯j‘¼#À—L\=µ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 > -- Connect with me on *http://twitter.com/jwage* <http://twitter.com/jwage> and http://about.me/jwage to keep in touch. Join OpenSky today: http://osky.co/l6a75g

« previous php.internals (#66199) next »