php.net |  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
Votes:7
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 23 = ?
Subscribe to this entry?

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-20 15:49 UTC] jhdxr@php.net
-Status: Open +Status: Duplicate
 [2016-04-20 15:49 UTC] jhdxr@php.net
duplicate of bug #69587.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 08:01:26 2019 UTC