php.net |  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
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 ...

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-02 22:26 UTC] nikic@php.net
Automatic comment on behalf of mail@pmmaga.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c6c1e75e6ba082b6d57f71c28d316b6db4fda6c7
Log: Fix bug #74607: Don't check for bi-directional compatibility in traits
 [2017-06-02 22:26 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC