Bug #76057 [Opn]: For DateTime the properties 'timezone' and 'timezone_type' are not set on init
| From: | jhdxr@php.net | Date: | Thu, 08 Mar 2018 14:49:17 +0000 |
| Subject: | Bug #76057 [Opn]: For DateTime the properties 'timezone' and 'timezone_type' are not set on init | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214237@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76057&edit=1
ID: 76057
Updated by: jhdxr@php.net
Reported by: projectcleverweb at gmail dot com
Summary: For DateTime the properties 'timezone' and
'timezone_type' are not set on init
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.2.3
Block user comment: N
Private report: N
New Comment:
This behavior (get timezone via property) is not expected, you should use
getTimezone()
to retrieve timezone.
Previous Comments:
------------------------------------------------------------------------
[2018-03-05 21:04:46] projectcleverweb at gmail dot com
Description:
------------
In short, these to properties are not set when the class is instantiated, but do become set when the
class is serialized OR when the property list is requested (such as via get_object_vars()).
You can see the conditions when timezone_type will be set on this page by just searching in the
browser for "timezone_type"
https://github.com/php/php-src/blob/ef255c9f0f2c2ad1ea224ed215edb00f5bc205bd/ext/date/php_date.c#L2269
This issue is occurring on PHP 5.6 and later (shown in the test script URL)
Test script:
---------------
https://3v4l.org/ZhQX9
--- OR ---
$test = new DateTime('2018-03-05 00:00:00', new DateTimeZone('UTC'));
var_dump($test->timezone); // Notice: Undefined property: DateTime::$timezone
get_object_vars($test);
var_dump($test->timezone); // string(3) "UTC"
Expected result:
----------------
string(3) "UTC"
string(3) "UTC"
Actual result:
--------------
Notice: Undefined property: DateTime::$timezone in /in/BQD1t on line 5
NULL
string(3) "UTC"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76057&edit=1