|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53097 Allow creating object without variable assignment and calling method inline
Submitted: 2010-10-18 14:59 UTC Modified: 2012-09-08 18:23 UTC
Avg. Score:4.6 ± 0.5
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:1 (14.3%)
From: cmanley at xs4all dot nl Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cmanley at xs4all dot nl
New email:
PHP Version: OS:


 [2010-10-18 14:59 UTC] cmanley at xs4all dot nl
In other languages I can do things like this, but PHP5 barfs when I try to do it:
print (new DateTime('now'))->format('Y-m-d H:i:s')

Instead I have to use a temporary variable:
$x = new DateTime('now');
print $x->format('Y-m-d H:i:s');

Test script:
php -r "print (new DateTime('now'))->format('Y-m-d H:i:s')" 

Expected result:
The date+time stamp.

Actual result:
PHP Parse error:  syntax error, unexpected T_OBJECT_OPERATOR in Command line code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-18 15:59 UTC]
As a workaround, you can do:

print date_create('now')->format('Y-m-d H:i:s'), "\n";
 [2010-10-19 13:50 UTC] cmanley at office dot caiw dot nl
Thanks, but that was simply an example. It could've been any (even user defined) class.
 [2011-11-11 10:51 UTC] cmanley at xs4all dot nl
Nice. It seems to be added in PHP 5.4 RC1 even though nobody seems to have handled 
this feature request I wasted my time on.
 [2012-09-08 18:23 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Mar 03 15:01:24 2021 UTC