From: Operating system: CentOS 5.4 PHP version: 5.3SVN-2010-03-08 (SVN) Package: Date/time related Bug Type: Bug Bug description:echo $dt->date doesn't work unless preceeded by print_r($dt)
Description: ------------ This example was taken straight from the DateTime::createFromFormat page at: http://www.php.net/manual/en/datetime.createfromformat.php After performing a DateTime::createFromFormat, the variable assigned doesn't seem to work. HOWEVER, the variable assigned DOES seem to work after being used in a print_r function. Please look at the test script and output. What am I doing wrong? Condensed Code Snippet: ======================= $format = 'Y-m-d'; $dt = DateTime::createFromFormat($format, '2009-02-03'); echo "<br>Format: $format; " . $dt->date . " (Should print \"2009-02-03 [time]\")<br>"; print_r($dt); echo "<br>Format: $format; " . $dt->date . " (Should print \"2009-02-03 [time]\")<br>"; Output: ======= Format: Y-m-d; (Should print "2009-02-03 [time]") DateTime Object ( [date] => 2009-02-03 06:23:24 [timezone_type] => 3 [timezone] => America/New_York ) Format: Y-m-d; 2009-02-03 06:23:24 (Should print "2009-02-03 [time]") Test script: --------------- Code Snippet: ============= $format = 'Y-m-d'; $dt = DateTime::createFromFormat($format, '2009-02-03'); echo "<br>Format: $format; " . $dt->date . " (Should print \"2009-02-03 [time]\")<br>"; Output: ======= Format: Y-m-d; (Should print "2009-02-03 [time]") DateTime Object ( [date] => 2009-02-03 06:23:24 [timezone_type] => 3 [timezone] => America/New_York ) Format: Y-m-d; 2009-02-03 06:23:24 (Should print "2009-02-03 [time]") Expected result: ---------------- Format: Y-m-d; 2009-02-03 06:23:24 (Should print "2009-02-03 [time]") Actual result: -------------- Format: Y-m-d; (Should print "2009-02-03 [time]") -- Edit bug report at http://bugs.php.net/bug.php?id=51234&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51234&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51234&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51234&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51234&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51234&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51234&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51234&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51234&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51234&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51234&r=support Expected behavior: http://bugs.php.net/fix.php?id=51234&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51234&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51234&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51234&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51234&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51234&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51234&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51234&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51234&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51234&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51234&r=mysqlcfg