php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75195 DateTimeInterface does not include add method
Submitted: 2017-09-12 17:06 UTC Modified: 2017-09-29 14:49 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: richard dot carree dot com at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: Irrelevant 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: richard dot carree dot com at gmail dot com
New email:
PHP Version: OS:

 

 [2017-09-12 17:06 UTC] richard dot carree dot com at gmail dot com
Description:
------------
Both of DateTime and DateTimeInterface expose `add` method. As "DateTimeInterface is meant so that both DateTime and DateTimeImmutable can be type hinted for", why it does not include `add` method?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-12 17:08 UTC] richard dot carree dot com at gmail dot com
Sorry, I meant:

Both of DateTime and DateTimeImmutable expose `add` method. As "DateTimeInterface is meant so that both DateTime and DateTimeImmutable can be type hinted for", why it does not include `add` method?
 [2017-09-29 09:05 UTC] heiglandreas@php.net
I wouldn't want to have it included in the interface as the implementation between both is different. Datetime returns itself, while DateTimeImmutable returns a new instance of Datetimeimmutable. So technically the return value is not the same…
 [2017-09-29 14:49 UTC] richard dot carree dot com at gmail dot com
Both return an object that implements DateTimeInterface.

Couldn't we have something like the following?

```
    /**
     * @return \DateTimeInterface
     */
    public function add(DateInterval $interval); 
```
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC