|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67934 DateInterval attributes not available until the object has been called
Submitted: 2014-08-29 16:23 UTC Modified: 2016-04-20 15:49 UTC
Avg. Score:3.6 ± 1.4
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:4 (66.7%)
From: rob dot lowcock at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 5.5.16 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: rob dot lowcock at gmail dot com
New email:
PHP Version: OS:


 [2014-08-29 16:23 UTC] rob dot lowcock at gmail dot com
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:
$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:

Actual result:
string: 'No matches'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-20 15:49 UTC]
-Status: Open +Status: Duplicate
 [2016-04-20 15:49 UTC]
duplicate of bug #69587.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 03 17:01:26 2020 UTC