Inheritance with Traits failed with error

Bug #64070 Inheritance with Traits failed with error
Submitted: 2013-01-25 11:23 UTC Modified: 2013-02-22 08:28 UTC
Votes:17
Avg. Score:4.7 ± 0.6
Reproduced:14 of 15 (93.3%)
Same Version:14 (100.0%)
Same OS:4 (28.6%)
From: denny dot reeh at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.11 OS:
Private report: No CVE-ID: None

 [2013-01-25 11:23 UTC] denny dot reeh at gmail dot com

Description:
------------
if two traits have the same function name and a trait uses another trait and using the as operator for aliases the function, it failed with fatal error.



Test script:
---------------
<?php
trait first_trait
{
    function first_function()
    {
        echo "From First Trait\n";
    }
}

trait second_trait
{
    use first_trait {
        first_trait::first_function as second_function;
    }

    function first_function()
    {
        echo "From Second Trait\n";
    }
}

class first_class
{
    use second_trait;
}

$obj = new first_class();
$obj->first_function();
$obj->second_function();

Expected result:
----------------
From Second Trait
From First Trait

Actual result:
--------------
PHP Fatal error:  Trait method first_function has not been applied, because there are collisions with other trait methods on first_class in test.php on line 25
PHP Stack trace:
PHP   1. {main}() /data/www/helix/test.php:0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2013-01-25 11:26 UTC] denny dot reeh at gmail dot com

example works with 5.4.10

 [2013-02-01 11:41 UTC] source dot spider at gmail dot com

@denny.reeh

OS: Win7/x64 

$ php --version
PHP 5.4.11 (cli) (built: Jan 16 2013 20:26:43)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

$ php .sandbox.php
PHP Fatal error:  Trait method first_function has not been applied, because 
there are collisions with other trait methods on first_class in ########## on 
line 25

Fatal error: Trait method first_function has not been applied, because there are 
collisions with other trait methods on first_class in ########## on line 25

 [2013-02-11 01:42 UTC] manchokapitancho at gmail dot com

This is also present in 5.4.12RC1.
Please, fix it before 5.4.12 rolls out.
This appears to be a regression.

 [2013-02-12 12:55 UTC] maciej dot sz at gmail dot com

This bug seemed to be also merged into 5.5 branch, tested with 5.5.0alpha4

 [2013-02-17 10:53 UTC] inefedor at gmail dot com

As far as I see this bug is resolved, could we close it?

 [2013-02-17 10:54 UTC] denny dot reeh at gmail dot com

resolved in which branch/release?

 [2013-02-17 12:05 UTC] denny dot reeh at gmail dot com

That can not be the solution.

I've reproduced that issue in 5.4.11, but it was working in 5.4.10

 [2013-02-18 10:41 UTC] inefedor at gmail dot com

Hi, I checked this problem with the master branch and yes, I was wrong, here's PR I attached to this bug, it solves the problem, but it won't work with xdebug extension. I'm not familiar with code of xdebug, I will contact with Derick about it.

 [2013-02-18 12:36 UTC] dmitry@php.net

-Status: Assigned +Status: Closed

 [2013-02-22 08:28 UTC] dmitry@php.net

The bug is definitely fixed, However I'm not sure if it's included into 5.4.12 release or not.

$ sapi/cli/php bug64070.php
From Second Trait
From First Trait
$ sapi/cli/php -v
PHP 5.4.13-dev (cli) (built: Feb 21 2013 16:29:23)

 [2013-02-26 10:25 UTC] alexander at mailinator dot net

Patch do not included in php 5.4.12.
But in php 5.4.13 branch bug fixed:

PHP 5.4.13-dev (cgi-fcgi) (built: Feb 24 2013 07:42:48)