Bug #64279 [Opn->Csd]: Using traits aliasing other traitmethods broken

From: Date: Sat, 23 Feb 2013 11:44:12 +0000
Subject: Bug #64279 [Opn->Csd]: Using traits aliasing other traitmethods broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-177348@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64279&edit=1

 ID:                 64279
 Updated by:         laruence@php.net
 Reported by:        r dot wilczek at web-appz dot de
 Summary:            Using traits aliasing other traitmethods broken
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux x86_64
 PHP Version:        5.4.12
-Assigned To:        
+Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

after a re-implemention of trait, the alias name was affected, also see: #64239


Previous Comments:
------------------------------------------------------------------------
[2013-02-22 16:12:56] r dot wilczek at web-appz dot de

err ... expected would be 

foo
bar

simply 
foo
would be nicer, but ok ..

------------------------------------------------------------------------
[2013-02-22 16:04:19] r dot wilczek at web-appz dot de

Tried the snapshot ...

Given the traits MyTrait, MyOtherTrait and the class Importer (see above), it shows this one:

$class = new \ReflectionClass('Importer');
foreach ($class->getMethods() as $method) {
    /* @var $method \ReflectionMethod */
    echo $method->getName() . PHP_EOL;
}

Expected result: 
foo

Actual result:
foo
foo

uh oh!

------------------------------------------------------------------------
[2013-02-22 15:36:00] laruence@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

seems the fix didn't goto 5.4.12

------------------------------------------------------------------------
[2013-02-22 15:28:15] r dot wilczek at web-appz dot de

Description:
------------
It is no longer possible to use a trait, which uses another trait and aliases methods.

This worked in PHP 5.4.10, but changed in either PHP 5.4.11 or PHP 5.4.12.

Test script:
---------------
<?php
trait MyTrait
{
	public function foo() {}
}

trait MyOtherTrait
{
    use MyTrait
    {
        foo as bar;
    }
}

class Importer
{
    use MyOtherTrait;
}
echo 'works' . PHP_EOL;

Expected result:
----------------
works

Actual result:
--------------
Fatal error: Trait method foo has not been applied, because there are collisions with other trait
methods on Importer in Example.php on line 18


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64279&edit=1


Thread (5 messages)

« previous php.bugs (#177348) next »