|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73683 DateInterval can no longer be accessed as array
Submitted: 2016-12-08 10:44 UTC Modified: 2016-12-08 13:14 UTC
From: sjon at hortensius dot net Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.1.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sjon at hortensius dot net
New email:
PHP Version: OS:


 [2016-12-08 10:44 UTC] sjon at hortensius dot net
I found another issue that was broken between RC6 and the final 7.1.0 release; this is probably broken by the fix for bug #69587

Test script:
$dp = new DateInterval('P2Y3W3D');
var_dump(isset($dp->d, $dp['d']));
echo $dp->d;

Expected result:

Actual result:
Fatal error: Uncaught Error: Cannot use object of type DateInterval as array in /in/XQOQD:4 Stack trace: #0 {main} thrown in /in/XQOQD on line 4
Process exited with code 255.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-08 12:51 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-12-08 12:51 UTC]
Indeed, the behavioral change has been introduced with commit 23f9e482[1] which *fixed* <>. However, the fact that the behavior has changed is not a bug, because isset($dp->d) should always have yielded TRUE, so the supplied test script relies on broken behavior.

[1] <;a=commit;h=23f9e482732b99f381e37afa77e04c2c480f372d>
 [2016-12-08 12:55 UTC] sjon at hortensius dot net
Maybe my test-script was too verbose; but are you saying array-access was broken intentionally? Why does this no longer work?

$dp = new DateInterval('P2Y3W3D');
 [2016-12-08 12:56 UTC] sjon at hortensius dot net
Ignore code in above comment; I meant:

$dp = new DateInterval('P2Y3W3D');
 [2016-12-08 13:01 UTC]
Array access on DateInterval objects never worked, see <>.
 [2016-12-08 13:14 UTC] sjon at hortensius dot net
you are right, thanks
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 09:01:29 2024 UTC