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: 2017-07-07 04:13 UTC
From: asj dot ricardo at gmail dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 7.1.7 OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC