php.net |  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
Votes:7
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cmanley at xs4all dot nl
New email:
PHP Version: OS:

 

 [2010-10-18 14:59 UTC] cmanley at xs4all dot nl
Description:
------------
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');
unset($x);


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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-18 15:59 UTC] derick@php.net
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
@derick
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] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC