php timezone returns empty array

2019-09-17 01:00发布

问题:

i have a server and a local development machine. On my locale machine, if I want to create a new DateTimezone with UTC, it's ok, the response:

php -r '$a = new \DateTimeZone("UTC"); var_dump($a);'
class DateTimeZone#1 (2) {
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(3) "UTC"
}

But on the other and on the server, if I type in this same command I get back this:

php -r '$a = new \DateTimeZone("UTC"); var_dump($a);'
object(DateTimeZone)#1 (0) {
}

In both cases date.timezone set to Europe/Berlin in apache2 and also in the cli config file.

Any idea?

回答1:

Ok, I found the problem since. The server had php 5.4 the local php 5.5, in 5.5 there is a __toString() method, in 5.4 it's not there yet.