php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55524 Traits should not be able to extend a class
Submitted: 2011-08-28 08:05 UTC Modified: 2011-08-29 15:54 UTC
From: gron@php.net Assigned: gron (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0alpha3 OS:
Private report: No CVE-ID: None
 [2011-08-28 08:05 UTC] gron@php.net
Description:
------------
Spotted by this post: http://zuttonet.com/articles/php-class-traits/

Traits build their own hierarchy of uses, but there is no useful semantics for 
extending classes.

For instance:


trait Foo extends Base {
    function bar() {}
}


The semantics for that is not defined (and actually at least broken for abstract 
methods).


This should give a fatal error as would the other way around (Base extends Foo).


Test script:
---------------
trait Foo extends Base {
    function bar() {}
}

Expected result:
----------------
Fatal error: A trait (Foo) cannot extend a class (Base) in %s on line %d


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-28 08:05 UTC] gron@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: gron
 [2011-08-29 01:03 UTC] kalle@php.net
Might also be worth checking the implements keyword if a user tries to implement an interface (or multiple)
 [2011-08-29 05:13 UTC] gron@php.net
Checking for interface is already done. As well as checking that classes do not 
extend traits. I only missed checking that traits do not extend classes, as far as 
I can tell. Plan to fix it later this week.
 [2011-08-29 15:53 UTC] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&revision=315712
Log: Fixed bug #55524 Traits should not be able to extend a class
# also used the Z_STRVAL where it seemed appropriate
 [2011-08-29 15:54 UTC] gron@php.net
This bug has been fixed in SVN.

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.

Fixed per svn rev 315712.
 [2011-08-29 15:54 UTC] gron@php.net
-Status: Assigned +Status: Closed
 [2012-04-18 09:49 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1f4dfded592909a162f4b590a25edc681e6b338d
Log: Fixed bug #55524 Traits should not be able to extend a class # also used the Z_STRVAL where it seemed appropriate
 [2012-07-24 23:40 UTC] rasmus@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1f4dfded592909a162f4b590a25edc681e6b338d
Log: Fixed bug #55524 Traits should not be able to extend a class # also used the Z_STRVAL where it seemed appropriate
 [2013-11-17 09:36 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1f4dfded592909a162f4b590a25edc681e6b338d
Log: Fixed bug #55524 Traits should not be able to extend a class # also used the Z_STRVAL where it seemed appropriate
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC