Bug #67934 [Opn->Dup]: DateInterval attributes not available until the object has been called

From: Date: Wed, 20 Apr 2016 15:49:41 +0000
Subject: Bug #67934 [Opn->Dup]: DateInterval attributes not available until the object has been called
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200664@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67934&edit=1 ID: 67934 Updated by: jhdxr@php.net Reported by: rob dot lowcock at gmail dot com Summary: DateInterval attributes not available until the object has been called -Status: Open +Status: Duplicate Type: Bug Package: Date/time related Operating System: Ubuntu PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: duplicate of bug #69587. Previous Comments: ------------------------------------------------------------------------ [2015-05-24 15:32:05] cmb@php.net Related To: Bug #69587 ------------------------------------------------------------------------ [2014-08-29 16:23:21] 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' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67934&edit=1

« previous php.bugs (#200664) next »