Evaluate arguments of new for classes without constructors

From: Date: Sat, 12 Mar 2016 16:01:41 +0000
Subject: Evaluate arguments of new for classes without constructors
Groups: php.internals 
Request: Send a blank email to internals+get-91642@lists.php.net to get a copy of this message
Hi internals, Currently class Foo {} new Foo(print 'xyz'); will not print "xyz", because the arguments to "new" are not evaluated if the class has no constructor. Conversely class Foo { function __construct() {} } new Foo(print 'xyz'); *will* print "xyz". This behavior is confusing, especially if the code is new $class(...) where $class may or may not have a constructor and thus the side effects of "..." may or may not occur, leading to a hard to identify failure mode. I do not believe this behavior is intentional, it is simply an artifact of the precise way in which "new" was implemented. HHVM does not implement "new" in this way, they always evaluate the arguments. We regularly get bug reports about this behavior. A sample of recent ones I was able to track down: #54162, #54170, #65930, #67829 and #70698. I'd like to fix this behavior, so that new arguments are always evaluated. Here's a patch: https://github.com/php/php-src/pull/1802 As this is technically a BC affecting change (even if of the lowest impact), I'm running it past the list first. Thanks, Nikita

« previous php.internals (#91642) next »