Edit report at http://bugs.php.net/bug.php?id=53097&edit=1

 ID:                 53097
 Comment by:         cmanley at office dot caiw dot nl
 Reported by:        cmanley at xs4all dot nl
 Summary:            Allow creating object without variable assignment
                     and calling method inline
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

@derick

Thanks, but that was simply an example. It could've been any (even user
defined) class.


Previous Comments:
------------------------------------------------------------------------
[2010-10-18 15:59:52] der...@php.net

As a workaround, you can do:



print date_create('now')->format('Y-m-d H:i:s'), "\n";

------------------------------------------------------------------------
[2010-10-18 14:59:35] 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


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53097&edit=1

Reply via email to