php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74872 First Trait wins on importing same methods with diff alias
Submitted: 2017-07-07 04:00 UTC Modified: 2020-03-06 10:21 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: asj dot ricardo at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.1.7 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: asj dot ricardo at gmail dot com
New email:
PHP Version: OS:

 

 [2017-07-07 04:00 UTC] asj dot ricardo at gmail dot com
Description:
------------
If we use:

use Trait1 {
    Trait1::init as private method1trait1;
}

use Trait2 
{
    Trait2::init as public method1trait2;
}

works.

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

	trait Trait1 
	{
            public function init()
	    {
	     	echo("Trait1 - init\n");
	    }
	}


	trait Trait2 
	{
            public function init()
	    {
	    	echo("Trait2 - init\n");
	    }
	}

	class Test 
	{
		use Trait1 {
		    init as private method1trait1;
		}

		use Trait2 
		{
		    init as public method1trait2;
		}

	        final public function __construct()
	        {
	    	    $this->init();
                    $this->method1trait1();
	            $this->method1trait2();
	        }
	    
	        public function init() 
	        {
	 		echo("Test - init\n");
	        }
	}

	$test = new Test();

	$reflection = new ReflectionClass( $test ); 

	foreach($reflection->getTraitAliases() as $k => $v)
	{
		echo $k.' => '.$v."\n";
	}

Expected result:
----------------
Test - init
Trait1 - init
Trait2 - init
method1trait1 => Trait1::init
method1trait2 => Trait2::init



Actual result:
--------------
Test - init
Trait1 - init
Trait1 - init
method1trait1 => Trait1::init
method1trait2 => Trait1::init



Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-07 04:13 UTC] requinix@php.net
-Status: Open +Status: Verified -PHP Version: 7.2.0alpha3 +PHP Version: 7.1.7
 [2020-03-06 10:21 UTC] nikic@php.net
-Status: Verified +Status: Duplicate
 [2020-03-06 10:21 UTC] nikic@php.net
Duplicate of bug #62069.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 03:01:28 2024 UTC