-1

I have many PHP files which are working fine in Azure. I recently shifted them to SmarterASP (with the same database, and properly connected) and then some of the same files show warning along with the output and that causes problems for the client. Here's one of the files:

<?php
$userTimeZone=$_GET['timezone'];
$offset=10;
$result['offset']=$offset;
$date=gmdate();
$date=date_create($date, new DateTimeZone("GMT"))
->setTimezone(new DateTimeZone($userTimeZone))->format("U");
$result['date']=$date;
echo json_encode($result);
?>

I get the correct output on Azure, provided the right input (?timezone=Asia/Kolkata):

{"offset":10,"date":"1505538838"}

But on SmarterASP, for the same input, I get this:

Warning: gmdate() expects at least 1 parameter, 0 given in H:\root\home\lazimsoftware-001\www\eeandroid\androidwebservice\getDateFromServer.php on line 5 {"offset":10,"date":"1505538926"}

This is one case, there are others too. Hope I find a solution here. Thanks.

Nithin
  • 221
  • 3
  • 14
  • 2
    Not sure how that PHP code would never work. The function `gmdate` expects the `$format` string argument. – ficuscr Sep 16 '17 at 05:58
  • 1
    If one server has errors and warnings off and the other on then one server may seem to work. – Andreas Sep 16 '17 at 06:10

1 Answers1

2

So, The function gmdate expects the $format string argument. Always has, just like date.

string gmdate ( string $format [, int $timestamp = time() ] )

The only thing that changed I think is that you are observing the warning it has always emitted. Assume your error levels or something have changed on new servers.

You code does return something like {"offset":10,"date":"1505541601"} but what you are passing to date_create is not what you intend. $date is actually Boolean false.

ficuscr
  • 6,975
  • 2
  • 32
  • 52
  • [Logging all errors](https://stackoverflow.com/questions/3531703/how-to-log-errors-and-warnings-into-a-file) and warnings offers great insight into issues like this where your code "works" but maybe not as expected. Log them in production and display them in dev/local. The warning is saying you need to fix that code and set the format for the `gmdate` function to use. Never heard of smarterASP. – ficuscr Sep 16 '17 at 06:08