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

Reply via email to