php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51234 echo $dt->date doesn't work unless preceeded by print_r($dt)
Submitted: 2010-03-08 12:28 UTC Modified: 2010-03-08 12:50 UTC
From: php at mpodr dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3SVN-2010-03-08 (SVN) OS: CentOS 5.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at mpodr dot com
New email:
PHP Version: OS:

 

 [2010-03-08 12:28 UTC] php at mpodr dot com
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]")

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-08 12:50 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2010-03-08 12:50 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #49382.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 31 23:01:30 2024 UTC