2015-09-28 60 views
0

我試圖讓DateTimeZone對象,將其設置方式如下:PHP DateTimeZone返回空對象

$dateTimeZoneRemote = new DateTimeZone('America/Edmonton'); 

但是打印出來返回一個空的對象?

print_r($dateTimeZoneRemote); 

回報:

DateTimeZone Object ()

運行PHP 5.2.17

+0

回聲'$ dateTimeZoneRemote'? – aldrin27

+0

什麼都不返回 – keeg

+2

什麼版本的PHP?我得到'DateTimeZone對象 ( [timezone_type] => 3 [timezone] => America/Edmonton )'on 5.6.4 – Phil

回答

4

這裏的問題是,print_r/var_dump/get_object_vars不顯示DateTimeZone的屬性,你的期望。這在PHP5.5中爲was a bug,fixed

無論如何,使用類提供的方法,您可以在任何版本中獲得正確的結果。

$dateTimeZoneRemote = new DateTimeZone('America/Edmonton'); 
echo $dateTimeZoneRemote->getName(); // print America/Edmonton 

https://3v4l.org/Nv9Ct