Bug #69977 [Ver]: overriding DateTime::add() and sub() issues warnings when using type hints

From: Date: Thu, 02 Jul 2015 12:11:33 +0000
Subject: Bug #69977 [Ver]: overriding DateTime::add() and sub() issues warnings when using type hints
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194063@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69977&edit=1

 ID:                 69977
 User updated by:    phofstetter at sensational dot ch
 Reported by:        phofstetter at sensational dot ch
 Summary:            overriding DateTime::add() and sub() issues warnings
                     when using type hints
 Status:             Verified
 Type:               Bug
 Package:            *General Issues
 Operating System:   Mac OS X
 PHP Version:        7.0.0alpha2
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2015-07-02 11:50:38] 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 11:20:51] cmb@php.net

Confirmed: <http://3v4l.org/oh0uT>.

Related to bug #61483.

------------------------------------------------------------------------
[2015-07-01 13:31:41] 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


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



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


Thread (6 messages)

« previous php.bugs (#194063) next »