php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75482 silent resolve/redefine trait conflict
Submitted: 2017-11-03 14:20 UTC Modified: 2017-11-03 15:08 UTC
From: bscheshir at gmail dot com Assigned: pmmaga (profile)
Status: Duplicate Package: Documentation problem
PHP Version: 7.2.0RC5 OS:
Private report: No CVE-ID: None
 [2017-11-03 14:20 UTC] bscheshir at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.traits
---
https://3v4l.org/g5HRH

how about same methods in C and C1?

this is some hard to understand 
and I can't find example in docs

Unexpected redefinition last(?)-trait method to class method

Test script:
---------------
<?php

trait ATrait {
    public function a(){
        return 'Aa';
    }
}

trait BTrait {
    public function a(){
        return 'Ba';
    }
}

class C {
    use ATrait{
        a as aa;
    }
    use BTrait{
        a as ba;
    }
    
    public function a() {
        return static::aa() . static::ba();
    }
}

$o = new C;
echo $o->a(), "\n";

class C1 {
    use BTrait{
        a as ba;
    }
    use ATrait{
        a as aa;
    }
    
    public function a() {
        return static::aa() . static::ba();
    }
}

$o = new C1;
echo $o->a(), "\n";

class D {
    use ATrait{
        ATrait::a as aa;
    }
    use BTrait{
        BTrait::a as ba;
    }
    
    public function a() {
        return static::aa() . static::ba();
    }
}

$o = new D;
echo $o->a(), "\n";


Actual result:
--------------
AaAa 
BaBa 
AaBa

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-03 14:48 UTC] pmmaga@php.net
-Status: Open +Status: Duplicate
 [2017-11-03 14:48 UTC] pmmaga@php.net
This is a duplicate of https://bugs.php.net/bug.php?id=74872
 [2017-11-03 15:08 UTC] pmmaga@php.net
-Assigned To: +Assigned To: pmmaga
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC