Edit report at http://bugs.php.net/bug.php?id=52535&edit=1
ID: 52535 Comment by: dcousineau at gmail dot com Reported by: webdeveloper02 at yahoo dot com Summary: DateTime::createFromFormat doesn't return a valid DateTime Object? Status: Open Type: Bug Package: Date/time related Operating System: linux 32/64-bit, os-x PHP Version: 5.3.3 Block user comment: N New Comment: Just as a side note, I also ran his snippet on my 5.3.1 install (stock OSX install) and received the same results. Previous Comments: ------------------------------------------------------------------------ [2010-08-04 21:34:57] webdeveloper02 at yahoo dot com Description: ------------ When creating a new DateTime object via DateTime::createFromFormat() the date / timezone_type and timezone methods return: PHP Notice: Undefined property: ...etc. If you var_dump() the object however and then call these methods they suddenly work / return what is expected. See test script for example. Test script: --------------- <?php /* PHP 5.3.2 / 5.3.3 (cli) */ date_default_timezone_set('America/New_York'); $x = '2010-07-21 20:49:07'; // $tz = new DateTimeZone('America/New_York'); // broken even with out this. // $y = DateTime::createFromFormat('Y-m-d H:i:s', $x, $tz); // doesn't make a difference. $y = DateTime::createFromFormat('Y-m-d H:i:s', $x); echo $y->date; // PHP Notice: Undefined property: DateTime::$date var_dump($y); // Something magical happens. echo $y->date; // Suddenly this works. ?> Expected result: ---------------- Would expect to see the proper output of calling $y->date on line #15 and not need to call var_dump($y) to get it to work? Actual result: -------------- # php tmp.php PHP Notice: Undefined property: DateTime::$date in /path/to/tmp.php on line 15 PHP Stack trace: PHP 1. {main}() /path/to/tmp.php:0 object(DateTime)#1 (3) { ["date"]=> string(19) "2010-07-21 20:49:07" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } 2010-07-21 20:49:07 # ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52535&edit=1