Sharon Levy wrote on 20/11/2014 00:34:
As a user, I like this feature since it seems sensible if one is concerned with efficient code execution. Whereas the undefined __construct {} permits the opcode to execute even tho' the resulting value is useless for the class. If anything needs to change, possibly it's the latter situation.

Note that there are many, many places where expressions are actioned for their side effects even though the result is discarded. The following will increment $a 3 times, even though it is discarded each time:

$a = 0;
++$a; // 1
class Foo { function __construct() {} }
new Foo(++$a); // 2
function bar() {}
bar(++$a); // 3
class WTF {}
new WTF(++$a); // suddenly, PHP becomes lazy

Test: http://3v4l.org/tcnv63 (note that HHVM increments all 4 times; PHP 4 only twice because class Foo has no old-style constructor)

Lazy evaluation certainly has benefits, but it's not, in general, a feature of PHP. That it happens in this one very specific case is what is so unexpected.
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to