0

I have really simple php code:

<?php
date_default_timezone_set('America/New_York'); 
echo (new DateTime())->format('r');
?>

and when I run it locally (thanks to xampp) it works fine and shows me the time:

Tue, 29 Sep 2015 11:41:35 -0400

but when I put it on my hosting webserver, I get the message:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in (...)/public_html/test/timeoftheserver.php on line 3

what might be the issue?

randomuser1
  • 2,733
  • 6
  • 32
  • 68
  • Support for this syntax was added in PHP 5.4.0 `Added class member access on instantiation (e.g. (new foo)->bar()) support.`.... is PHP 5.4 is now EOL and only supported for security fixes, you really should be pushing your hosting to update to a supported version of PHP – Mark Baker Sep 29 '15 at 15:56
  • Many hosting providers offer this as an option, somewhere in your hosting account settings you can likely choose your PHP version, make sure it is >= 5.4.0 – stolli Sep 29 '15 at 16:45

1 Answers1

1

I suspect one is a lower version of PHP. This should work on either:

<?php
date_default_timezone_set('America/New_York'); 
$d = new DateTime();
echo $d->format('r');
?>
Christian
  • 1,557
  • 11
  • 16