I have the following code:
<?php
$date = new DateTime;
var_dump($date);
$date->timezone = 'Europe/Madrid';
var_dump($date->timezone); // Shows 'Europe/Madrid'
var_dump($date); // Shows 'UTC' (!)
var_dump($date->timezone); // Shows 'UTC' (!!)
which shows the following output:
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-11-08 21:21:15.596968"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
string(13) "Europe/Madrid"
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-11-08 21:21:15.596968"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
string(3) "UTC"
Why $date->timezone
changes back from 'Europe/Madrid' to 'UTC' when I do a simple var_dump($date)
???
Using print_r()
instead of var_dump()
has the same result.