|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-04 21:40 UTC] dcousineau at gmail dot com
[2010-08-04 22:00 UTC] rasmus@php.net
-Status: Open
+Status: Verified
-Assigned To:
+Assigned To: derick
[2010-08-04 22:09 UTC] webdeveloper02 at yahoo dot com
[2010-08-04 23:18 UTC] webdeveloper02 at yahoo dot com
-Status: Verified
+Status: Closed
[2010-08-04 23:18 UTC] webdeveloper02 at yahoo dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 21:00:02 2025 UTC |
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 #