Bug #74607 [NEW]: Traits enforce different inheritance rules
| From: | mail at pmmaga dot net | Date: | Wed, 17 May 2017 22:07:00 +0000 |
| Subject: | Bug #74607 [NEW]: Traits enforce different inheritance rules | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-209171@lists.php.net to get a copy of this message | ||
From: mail at pmmaga dot net
Operating system: *
PHP version: 7.0.19
Package: Class/Object related
Bug Type: Bug
Bug description:Traits enforce different inheritance rules
Description:
------------
When inheriting from an abstract class, a method implemented by a trait
does not allow adding a return type. This is allowed when the method is
implemented directly in the child class.
On the current master (7.2) the same happens when omitting a type-hint.
With interfaces the behavior is consistent with or without traits.
Test script:
---------------
<?php
abstract class L1{
abstract function m3($x);
}
trait L2t{
function m3($x): int{}
}
class L2 extends L1{
use L2t;
}
Expected result:
----------------
N/A
Actual result:
--------------
Fatal error: Declaration of L2t::m3($x): int must be compatible with
L1::m3($x) in ...
--
Edit bug report at https://bugs.php.net/bug.php?id=74607&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74607&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74607&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74607&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74607&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74607&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74607&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74607&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74607&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74607&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74607&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74607&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74607&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74607&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74607&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74607&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74607&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74607&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74607&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74607&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74607&r=mysqlcfg