|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70472 prevent trait to be used when conflicts can't be resolved
Submitted: 2015-09-10 19:34 UTC Modified: 2017-08-05 04:47 UTC
From: youwishspambot at example dot orgy Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 7.0.0RC2 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
39 - 32 = ?
Subscribe to this entry?

 [2015-09-10 19:34 UTC] youwishspambot at example dot orgy
Example 1:


class A{}
class B{}

trait X{
    abstract function test(B $b);
    function doSomething(){
        // can only be B. nothing should be allowed to change the signature of test(B)
        $this->test(new B);

interface Contract{
    function test(A $a);

class Implementation implements Contract{
    use X; // incompatible, but compiles
    function test(A $a){}


Example 2:


class A{}
class B{}

trait X{
    function tryA(A $a){
    function test(A $a){} // can't solve signatures incompatibility...

trait Y{
    function tryB(B $b){
    function test(B $b){} // ...when arguments are different

class Example{
    use X, Y{
        X::test insteadof Y; // this doesn't actually solve anything

class A{}
class B{}

$x = new Example;
$x->tryA(new A);
$x->tryB(new B);

(insteadof can only work if resolution happens between two identical signatures)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-10 19:46 UTC]
-Type: Bug +Type: Feature/Change Request -Package: PHP Language Specification +Package: Scripting Engine problem
 [2017-08-05 04:47 UTC]
-Status: Open +Status: Suspended
 [2017-08-05 04:47 UTC]
Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list ( as an RFC. Please read the guide about creating RFCs here:
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list ( and/or solicit help from one of the experienced developers. 

Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:21 2019 UTC