Bug #60873 [NEW]: some inspections of DateTime member variables cause creation, can break asserts

From: Date: Tue, 24 Jan 2012 22:19:26 +0000
Subject: Bug #60873 [NEW]: some inspections of DateTime member variables cause creation, can break asserts
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166771@lists.php.net to get a copy of this message
From: Operating system: n/a PHP version: 5.3.9 Package: Date/time related Bug Type: Bug Bug description:some inspections of DateTime member variables cause creation, can break asserts 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 -- Edit bug report at https://bugs.php.net/bug.php?id=60873&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60873&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60873&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60873&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60873&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60873&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60873&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60873&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60873&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60873&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60873&r=support Expected behavior: https://bugs.php.net/fix.php?id=60873&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60873&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60873&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60873&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60873&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60873&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60873&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60873&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60873&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60873&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60873&r=mysqlcfg

« previous php.bugs (#166771) next »