Bug #49382 [Com]: can't access DateTime->date
| From: | valterms at gmail dot com | Date: | Wed, 06 Jul 2016 10:42:28 +0000 |
| Subject: | Bug #49382 [Com]: can't access DateTime->date | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202092@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=49382&edit=1
ID: 49382
Comment by: valterms at gmail dot com
Reported by: klawd at kamundo dot de
Summary: can't access DateTime->date
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Debian GNU/Linux 5.0
PHP Version: 5.3.0
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
How I worked around the problem:
...
$dt=new DateTime('2016-07-06 00:00:00');
$tmpObj = (array)($dt); // Only for circumvention, without this line $dt->date return null.
$dtx = $dt->date;
echo $dtx; // display: 2016-07-06 00:00:00
...
Previous Comments:
------------------------------------------------------------------------
[2015-12-23 04:03:32] novell at att dot net
This may be a duplicate comment - my system hiccuped and I'm not sure the first one was
actually sent.
print_r also causes the date element of DateTime object to be available the "wrong" way.
http://stackoverflow.com/questions/34427627/very-interesting-behavior-of-a-datetime-object-and-access-to-its-elements-bi
------------------------------------------------------------------------
[2014-12-08 17:48:27] phpbug at sirdiego dot de
Okay, so I don't know if this is new or relevant in any case, but I found something similar to
var_dump.
php > $object = new \DateTime();
php > echo $object->date . PHP_EOL;
PHP Notice: Undefined property: DateTime::$date in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
php > get_object_vars($object);
php > echo $object->date . PHP_EOL;
2014-12-08 18:44:15
For me this also an unexpected side-effect and would say it is a bug.
------------------------------------------------------------------------
[2013-07-09 11:35:13] weirdan at gmail dot com
I'd say the bug is not that the property is not present before var_dump'ing
object, but that the property is suddenly created. Unexpected side-effect.
------------------------------------------------------------------------
[2013-07-09 11:29:41] hanskrentel at yahoo dot de
I wonder how this qualifies as a bug as any object can have variable properties
and accessing undefined ones give notices.
Just sounds like standard PHP behavior here.
------------------------------------------------------------------------
[2012-12-29 17:56:02] info at metashock dot net
I think it is interesting that the property can be accessed using reflection. Using the following
example I can access the property:
$dt = new DateTime();
$o = new ReflectionObject($dt);
$p = $o->getProperty('date');
$date = $p->getValue($dt)); // returns the value of DateTime::$date
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=49382
--
Edit this bug report at https://bugs.php.net/bug.php?id=49382&edit=1