I suddenly get the error message Fatal error: Call to a member function setTimezone() on a non-object after adding some new lines of code:
first of all, i used DateTime to switch between different timeformats to calculate DST, etc.
I used the following code [Code Block 1]
foreach ($result as $k=>$v)
{$timestamp=DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $k,new DateTimeZone("UTC")); //take current date from $k as new DateTile Object
$timestamp->setTimezone(new DateTimeZone('Europe/Berlin')); //convert timezone
$date[]=$timestamp->format('Y-m-d H:i:s'); // "export" the date to date-array
}
This code works well, until now:
I added 20 code lines above an other DateTime function [Code Block 2]:
$ts=new DateTime("@".round($_GET['startdate']/1000));
$startdate=$ts->format('Y-m-d\TH:i:s.u\Z');
After I added these 2 lines, all the time i get the error: Fatal error: Call to a member function setTimezone()for this line:$timestamp->setTimezone(new DateTimeZone('Europe/Berlin'));
…but i can’t see an relation / connection between these to code parts?!
What’s happened here?
Thank you, for any idea.
//Update: as you can see at the comments, i’m using PHP 5.3.6
again: the code block 1 works, if i remove the code block 2
Looks like not all of array keys of
$resultis valid date strings. The DateTime class returns a new DateTime instance or FALSE on failure. And when$kis not valid,$timestampis false, which is not an object.