|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74607 Traits enforce different inheritance rules
Submitted: 2017-05-17 22:06 UTC Modified: 2017-05-19 14:58 UTC
From: mail at pmmaga dot net Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.0.19 OS: *
Private report: No CVE-ID: None
 [2017-05-17 22:06 UTC] mail at pmmaga dot net
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:

abstract class L1{ 
abstract function m3($x);

trait L2t{ 
function m3($x): int{}

class L2 extends L1{ 
use L2t; 

Expected result:

Actual result:
Fatal error: Declaration of L2t::m3($x): int must be compatible with L1::m3($x) in ...


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-02 22:26 UTC]
Automatic comment on behalf of
Log: Fix bug #74607: Don't check for bi-directional compatibility in traits
 [2017-06-02 22:26 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC