ID: 40300 Updated by: [EMAIL PROTECTED] Reported By: finalvoid at gmail dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Windows XP PHP Version: 5.2.0 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This syntax is simply not supported. Previous Comments: ------------------------------------------------------------------------ [2007-02-01 00:28:12] finalvoid at gmail dot com 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 this bug report at http://bugs.php.net/?id=40300&edit=1