keeg
keeg

Reputation: 3978

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

Upvotes: 0

Views: 217

Answers (1)

Federkun
Federkun

Reputation: 36924

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

Upvotes: 4

Related Questions