|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 18:00:01 2025 UTC |
As a workaround, you can do: print date_create('now')->format('Y-m-d H:i:s'), "\n";