Req #53097 [Opn]: Allow creating object without variable assignment and calling method inline

From: Date: Mon, 18 Oct 2010 13:59:53 +0000
Subject: Req #53097 [Opn]: Allow creating object without variable assignment and calling method inline
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155299@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53097&edit=1

 ID:                 53097
 Updated by:         derick@php.net
 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:

As a workaround, you can do:

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


Previous Comments:
------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#155299) next »