php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64279 Using traits aliasing other traitmethods broken
Submitted: 2013-02-22 15:28 UTC Modified: 2013-02-23 11:44 UTC
From: r dot wilczek at web-appz dot de Assigned: laruence (profile)
Status: Closed Package: *General Issues
PHP Version: 5.4.12 OS: Linux x86_64
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: r dot wilczek at web-appz dot de
New email:
PHP Version: OS:

 

 [2013-02-22 15:28 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-22 15:36 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-02-22 15:36 UTC] 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 16:04 UTC] r dot wilczek at web-appz dot de
-Status: Feedback +Status: Open
 [2013-02-22 16:04 UTC] 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 16:12 UTC] r dot wilczek at web-appz dot de
err ... expected would be 

foo
bar

simply 
foo
would be nicer, but ok ..
 [2013-02-23 11:44 UTC] laruence@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2013-02-23 11:44 UTC] laruence@php.net
after a re-implemention of trait, the alias name was affected, also see: #64239
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 17:02:17 2025 UTC