|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69977 overriding DateTime::add() and sub() issues warnings when using type hints
Submitted: 2015-07-01 13:31 UTC Modified: 2018-03-29 17:18 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: phofstetter at sensational dot ch Assigned:
Status: Suspended Package: Date/time related
PHP Version: 7.0.0alpha2 OS: Mac OS X
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-07-01 13:31 UTC] phofstetter at sensational dot ch
When you subclass DateTime, PHP insists on there being no type hint present for `add()` and `sub()`. If you type-hint them to `DateInterval`, php throws a warning about the signature not matching the parent, even though the manual (and reality agrees) says that the argument is a DateTimeInterval.

While I would personally love for this warning to be turnoaffable or at least not be a warning but a notice, it certainy shouldn't warn for correct usage.

As it stands now, code that was using type hints issues warnings until the type hints are removed, even though DateTime::add() also issues a warning if you pass anything but a DateInterval as an argument.

Test script:

class Foo extends DateTime {
    function add(DateInterval $interval){ parent::add($interval); }

Expected result:
no output. No warning

Actual result:
PHP Warning:  Declaration of Foo::add() should be compatible with DateTime::add($interval) in foo.php on line 5


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-02 11:20 UTC]
-Status: Open +Status: Verified
 [2015-07-02 11:20 UTC]
Confirmed: <>.

Related to bug #61483.
 [2015-07-02 11:50 UTC] phofstetter at sensational dot ch
Ah. I see- Yes. This is probably a duplicate of #61483, but in PHP7, what was once an E_STRICT error has been promoted to an E_WARNING.
 [2015-07-02 12:11 UTC] phofstetter at sensational dot ch
Looking at the code, I would say that this caused by all ARG_INFO block lacking a call to ZEND_ARG_OBJ_INFO. Is there a reason why this is missing? Would you accept a PR adding them as needed for PHP7? Would this require an RFC?

Now that the old E_STRICT notice has been upgraded to an E_WARNING combined with the much better type hinting support in PHP7, this has become much more important than before IMHO.
 [2015-07-02 12:36 UTC]
Yes, Philip, you're right: the ZEND_ARG_OBJ_INFO calls are
missing. And maybe ZEND_ARG_TYPE_INFO calls should be added for
the scalars as well.

As this change would constitute a BC break, it seems it needs
discussion on the internals@ mailing list.
 [2015-07-02 16:26 UTC]
-Status: Verified +Status: Suspended
 [2015-07-02 16:26 UTC]
According to the discussion on internals@[1] I'm suspending this

[1] <>
 [2018-03-29 17:18 UTC]
-Package: *General Issues +Package: Date/time related
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 19:01:28 2023 UTC