Req #75195 [Opn->Nab]: DateTimeInterface does not include add method

From: Date: Fri, 20 May 2022 14:36:06 +0000
Subject: Req #75195 [Opn->Nab]: DateTimeInterface does not include add method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241565@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75195&edit=1

 ID:                 75195
 Updated by:         derick@php.net
 Reported by:        richard dot carree dot com at gmail dot com
 Summary:            DateTimeInterface does not include add method
-Status:             Open
+Status:             Not a bug
 Type:               Feature/Change Request
 Package:            Date/time related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

The current interface correctly does not include "add", as the behaviour is not the same
(self, vs a new instance returned).


Previous Comments:
------------------------------------------------------------------------
[2017-09-29 14:49:21] 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); 
```

------------------------------------------------------------------------
[2017-09-29 09:05:38] 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-12 17:08:01] 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-12 17:06:10] 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?



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75195&edit=1


Thread (5 messages)

« previous php.bugs (#241565) next »