|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-04-20 15:49 UTC] jhdxr@php.net
-Status: Open
+Status: Duplicate
[2016-04-20 15:49 UTC] jhdxr@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
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'