Bug #67934 [NEW]: DateInterval attributes not available until the object has been called
| From: | rob dot lowcock at gmail dot com | Date: | Fri, 29 Aug 2014 16:23:22 +0000 |
| Subject: | Bug #67934 [NEW]: DateInterval attributes not available until the object has been called | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187339@lists.php.net to get a copy of this message | ||
From: rob dot lowcock at gmail dot com
Operating system: Ubuntu
PHP version: 5.5.16
Package: Date/time related
Bug Type: Bug
Bug description:DateInterval attributes not available until the object has been called
Description:
------------
If a DateInterval is created using date_diff, the public attributes of
the interval object return true on an empty check. However, if the
object is called elsewhere first (for example, in a var_dump() or
json_encode()) the attributes can be tested with empty().
Tested on 5.3.3 and 5.5.9-ubuntu.
Test script:
---------------
<?php
$date = new DateTime('2014-08-25');
$today = new DateTime('2014-08-29');
$interval = date_diff($date, $today);
// json_encode($interval);
if (!empty($interval->days)) {
echo $interval->days;
} else if (!empty($interval->h)) {
echo $interval->h;
} else {
echo 'No matches';
}
Expected result:
----------------
4
Actual result:
--------------
string: 'No matches'
--
Edit bug report at https://bugs.php.net/bug.php?id=67934&edit=1
--