简体   繁体   中英

PHP DateTimeZone returns empty object

I'm trying to get DateTimeZone object, setting it the following way:

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

However printing it out returns an empty object??

print_r( $dateTimeZoneRemote );

returns:

DateTimeZone Object ( )

Running 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. This was a bug , fixed in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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