简体   繁体   English

PHP DateTimeZone返回空对象

[英]PHP DateTimeZone returns empty object

I'm trying to get DateTimeZone object, setting it the following way: 我正在尝试获取DateTimeZone对象,通过以下方式进行设置:

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

However printing it out returns an empty object?? 但是打印出来会返回一个空对象?

print_r( $dateTimeZoneRemote );

returns: 收益:

DateTimeZone Object ( )

Running PHP 5.2.17 运行PHP 5.2.17

The problem here is that print_r / var_dump / get_object_vars don't show the properties of DateTimeZone as you expect. 这里的问题是, print_r / var_dump / get_object_vars并未按预期显示DateTimeZone的属性。 This was a bug , fixed in PHP 5.5. 是一个错误 ,已在PHP 5.5中修复

Whatever, using the methods that the class provide, you get the correct result in any version. 无论如何,使用该类提供的方法,您都可以在任何版本中获得正确的结果。

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

https://3v4l.org/Nv9Ct https://3v4l.org/Nv9Ct

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM