php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phofstetter at sensational dot ch
New email:
PHP Version: OS:

 

 [2015-07-01 13:31 UTC] phofstetter at sensational dot ch
Description:
------------
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:
---------------
<?php

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-02 11:20 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-07-02 11:20 UTC] cmb@php.net
Confirmed: <http://3v4l.org/oh0uT>.

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] cmb@php.net
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] cmb@php.net
-Status: Verified +Status: Suspended
 [2015-07-02 16:26 UTC] cmb@php.net
According to the discussion on internals@[1] I'm suspending this
ticket.

[1] <http://markmail.org/thread/usxbhcup2fmqyb2x>
 [2018-03-29 17:18 UTC] cmb@php.net
-Package: *General Issues +Package: Date/time related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC