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

From: Date: Thu, 02 Jul 2015 11:20:52 +0000
Subject: Bug #69977 [Opn->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-194060@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
 Updated by:         cmb@php.net
 Reported by:        phofstetter at sensational dot ch
 Summary:            overriding DateTime::add() and sub() issues warnings
                     when using type hints
-Status:             Open
+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:

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

Related to bug #61483.


Previous Comments:
------------------------------------------------------------------------
[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 (#194060) next »