View Single Post
Old 01-25-2009, 06:26 AM   #1
Verdagon
Junior Member
 
Join Date: Jul 2004
Posts: 15
resolved [RESOLVED] new Anything()->aMethod()

Hey everyone, why does this not work?

Code:
echo new DateTime()->getOffset();
I get this error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'

it seems like the -> operator only works when theres a $ somewhere before it in the line. Are there any simpler workarounds than saying this?:

Code:
$d = new DateTime();
echo $d->getOffset();
(it's not just with the DateTime, its with any object and any method. seems like new Anything()->aMethod() never works)

It would seem like a pretty common thing, and I tried searching for the answer, but I couldn't come up with the right keywords... and google strips out -> and ()...

Thanks for your comments,

- Evan
__________________
"You're still alive?! But I paid them so much..." -Verdagon

Last edited by Verdagon; 01-25-2009 at 06:33 AM. Reason: Fixed the semicolon
Verdagon is offline   Reply With Quote