|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-07-09 10:41 UTC] hanskrentel at yahoo dot de
[2013-07-09 13:42 UTC] kavi at postpro dot net
[2013-07-09 19:08 UTC] kavi at postpro dot net
[2013-07-09 23:19 UTC] hanskrentel at yahoo dot de
[2013-07-10 00:59 UTC] kavi at postpro dot net
[2013-07-17 15:19 UTC] jglover at wilanddirect dot com
[2017-01-17 07:02 UTC] heiglandreas@php.net
-Status: Open
+Status: Not a bug
[2017-01-17 07:02 UTC] heiglandreas@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 08:00:01 2025 UTC |
Description: ------------ DateTime objects have a timezone_type member variable. This appears to differ based on whether the timezone was set by passing a DateTimeZone object to the DateTime constructor vs the constructor parsing it out of a string. The timezone_type member variable is not mentioned anywhere in the documentation, nor is this behavior. Further, inspecting DateTime objects with print_r and other interrogations can cause the timezone_type properties to be created. Equality operator comparisons still work when timezone_type properties created and are different, but isEqual in SimpleTest (for example) does not, nor presumably will other object comparisons which don't use what I imagine to be DateTime's overloaded comparison operators. Please document the timezone_type member variable of DateTime and address the unexpected behavior of member variable creation upon inspection. Test script: --------------- <?php $a = new DateTime('2010-01-01 08:45:00', new DateTimeZone('UTC')); $str = $a->format(DateTime::ISO8601); $b = new DateTime($str, new DateTimeZone('UTC')); echo "\n"; echo "a->timezone_type: " . $a->timezone_type . "\n"; echo "b->timezone_type: " . $b->timezone_type . "\n"; echo "\na: " . print_r($a, true) . "\n"; echo "\nstr: $str\n"; echo "b: " . print_r($b, true) . "\n"; echo "a->timezone_type: " . $a->timezone_type . "\n"; echo "b->timezone_type: " . $b->timezone_type . "\n"; $eq = ($a == $b); echo "\na == b: $eq\n"; Expected result: ---------------- $ php test.php a->timezone_type: 3 b->timezone_type: 1 a: DateTime Object ( [date] => 2010-01-01 08:45:00 [timezone_type] => 3 [timezone] => UTC ) str: 2010-01-01T08:45:00+0000 b: DateTime Object ( [date] => 2010-01-01 08:45:00 [timezone_type] => 1 [timezone] => +00:00 ) a->timezone_type: 3 b->timezone_type: 1 a == b: 1 Actual result: -------------- $ php test.php a->timezone_type: b->timezone_type: a: DateTime Object ( [date] => 2010-01-01 08:45:00 [timezone_type] => 3 [timezone] => UTC ) str: 2010-01-01T08:45:00+0000 b: DateTime Object ( [date] => 2010-01-01 08:45:00 [timezone_type] => 1 [timezone] => +00:00 ) a->timezone_type: 3 b->timezone_type: 1 a == b: 1