php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: denny dot reeh at gmail dot com
New email:
PHP Version: OS:

 

 [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

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 11:11 UTC] inefedor at gmail dot com
I can't find exact commit, but it works at least on 5.4.9 ( http://codepad.viper-7.com/GOqBix ).
 [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:40 UTC] laruence@php.net
-Assigned To: +Assigned To: dmitry
 [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-18 12:36 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=42437dd870de28eee6c9127f4c7e7c78ba8e0152
Log: Fixed bug #64070 (Inheritance with Traits failed with error)
 [2013-02-18 12:37 UTC] dmitry@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2013-02-21 22:16 UTC] alexander at mailinator dot net
Problem has not solved yet. Test snapshot http://windows.php.net/downloads/snaps/php-5.4/r86c1a26/
and bug still present in it.
 [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)
 [2014-10-07 23:20 UTC] stas@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=42437dd870de28eee6c9127f4c7e7c78ba8e0152
Log: Fixed bug #64070 (Inheritance with Traits failed with error)
 [2014-10-07 23:31 UTC] stas@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=42437dd870de28eee6c9127f4c7e7c78ba8e0152
Log: Fixed bug #64070 (Inheritance with Traits failed with error)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 11:01:27 2024 UTC