php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sjon at hortensius dot net
New email:
PHP Version: OS:

 

 [2016-12-08 10:44 UTC] sjon at hortensius dot net
Description:
------------
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:
----------------
bool(true)
3

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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-08 12:51 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-12-08 12:51 UTC] cmb@php.net
Indeed, the behavioral change has been introduced with commit 23f9e482[1] which *fixed* <https://bugs.php.net/69587>. 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] <http://git.php.net/?p=php-src.git;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');
var_dump(isset($dp->d));
 [2016-12-08 12:56 UTC] sjon at hortensius dot net
Ignore code in above comment; I meant:

$dp = new DateInterval('P2Y3W3D');
var_dump(isset($dp['d']));
 [2016-12-08 13:01 UTC] cmb@php.net
Array access on DateInterval objects never worked, see <https://3v4l.org/BKvVE>.
 [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: Fri Mar 29 13:01:29 2024 UTC