Bug #64070 [Opn]: Inheritance with Traits failed with error

From: Date: Fri, 25 Jan 2013 11:26:34 +0000
Subject: Bug #64070 [Opn]: Inheritance with Traits failed with error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-176237@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64070&edit=1

 ID:                 64070
 User updated by:    denny dot reeh at gmail dot com
 Reported by:        denny dot reeh at gmail dot com
 Summary:            Inheritance with Traits failed with error
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        5.4.11
 Block user comment: N
 Private report:     N

 New Comment:

example works with 5.4.10


Previous Comments:
------------------------------------------------------------------------
[2013-01-25 11:23:43] 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



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



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


Thread (15 messages)

« previous php.bugs (#176237) next »