Bug #69977 [NEW]: overriding DateTime::add() and sub() issues warnings when using type hints
From: phofstetter at sensational dot ch
Operating system: Mac OS X
PHP version: 7.0.0alpha2
Package: *General Issues
Bug Type: Bug
Bug description:overriding DateTime::add() and sub() issues warnings when using type hints
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 bug report at https://bugs.php.net/bug.php?id=69977&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69977&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69977&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69977&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69977&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69977&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69977&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69977&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69977&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69977&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69977&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69977&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69977&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69977&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69977&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69977&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69977&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69977&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69977&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69977&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69977&r=mysqlcfg
Thread (6 messages)
- phofstetter at sensational dot ch