From: finalvoid at gmail dot com Operating system: Windows XP PHP version: 5.2.0 PHP Bug Type: Class/Object related Bug description: Calling a function on a newly created object doesn't work
Description: ------------ Calling a function on a newly created object requires saving the object to a variable. Script that clarifies what I'm trying to say: class C { public function __construct() {} public function f() { return 1234; } }; $y = (new C())->f(); print($y); The above doesn't work. However, it does work if you replace the penultimate line with $x = new C(); $y = $x->f(); If we add parentheses around the $x, i.e. $y = ($x)->f(); then it still doesn't work. This and bug report #9587 indicate that the actual underlying cause is that object-valued variables are implemented, but object-valued expressions are not. Although the "this is not a bug" comment on the above-cited bug report #9587 did not include a rationale, it's difficult for me to decide whether it applies here as well; maybe this bug report should actually be a feature request? Personally, as a PHP rookie but Java veteran, I would say that object-valued expressions SHOULD work, and they DON'T, therefore it's a BUG. Thanks! Reproduce code: --------------- class C { public function __construct() {} public function f() { return 1234; } }; $y = (new C())->f(); print($y); Expected result: ---------------- 1234 Actual result: -------------- Parse error: parse error, unexpected T_OBJECT_OPERATOR in c:\path\test.php on line 5 -- Edit bug report at http://bugs.php.net/?id=40300&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40300&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40300&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40300&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40300&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40300&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40300&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40300&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40300&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40300&r=support Expected behavior: http://bugs.php.net/fix.php?id=40300&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40300&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40300&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40300&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40300&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40300&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40300&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40300&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40300&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40300&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40300&r=mysqlcfg