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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC