Bug #74607 [Com]: Traits enforce different inheritance rules
| From: | levim@php.net | Date: | Fri, 19 May 2017 15:00:13 +0000 |
| Subject: | Bug #74607 [Com]: Traits enforce different inheritance rules | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209195@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74607&edit=1
ID: 74607
Comment by: levim@php.net
Reported by: mail at pmmaga dot net
Summary: Traits enforce different inheritance rules
Status: Open
Type: Bug
Package: Class/Object related
Operating System: *
PHP Version: 7.0.19
Block user comment: N
Private report: N
New Comment:
Here is the exact branch that is being taken on master:
https://github.com/php/php-src/blob/372397f518bf6de04a973b7ca52ae724b6f56bd6/Zend/zend_inheritance.c#L1187-L1194
Previous Comments:
------------------------------------------------------------------------
[2017-05-17 22:06:58] mail at pmmaga dot net
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 this bug report at https://bugs.php.net/bug.php?id=74607&edit=1