On 02/25/2013 08:14 AM, Nikita Popov 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 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.
I think a brief RFC would be good to clarify and give some more examples of what "any expression" is. Seeing more examples would help people evaluate the impact and see the use cases. It would also help the doc process. (For me, it's changes like Sara's trailing comma proposal that are too small to have needed an RFC) Chris
Thoughts? Nikita
-- christopher.jo...@oracle.com http://twitter.com/ghrd Newly updated, free PHP & Oracle book: http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php