php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60911 Confusing error message when extending traits
Submitted: 2012-01-28 05:23 UTC Modified: 2012-03-04 18:33 UTC
From: [email protected] Assigned: gron (profile)
Status: Closed Package: *General Issues
PHP Version: 5.4.0RC6 OS: OSX 10.7.2
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: [email protected]
New email:
PHP Version: OS:

 

 [2012-01-28 05:23 UTC] [email protected]
Description:
------------
While I know it should not be possible to have a trait extend another trait, the 
error message is confusing, stating that you are trying to extend a class.

I understand that "use" is the correct answer to the problem the script is trying 
to solve.

Test script:
---------------
<?php
trait Foo { }

trait Bar extends Foo { }

Expected result:
----------------
Fatal error: A trait (Bar) cannot extend a trait (Foo) in ...

Better yet:

Fatal error: A trait (Bar) cannot extend a trait (Foo), use "use" instead in ...

or some such.

Actual result:
--------------
Fatal error: A trait (Bar) cannot extend a class in ...

Patches

extend-error-msg.patch (last revision 2012-01-31 10:01 UTC by [email protected])

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-31 04:02 UTC] [email protected]
actually this is difficult to achieve, think about:

a.php
<?php
trait Foo { }
?>

index.php
<?php
require "a.php";
trait Bar extends Foo { }
?>

then you can not get any info of Foo while parsing index.php
 [2012-01-31 04:02 UTC] [email protected]
-Status: Open +Status: Wont fix -Type: Bug +Type: Feature/Change Request
 [2012-01-31 10:01 UTC] [email protected]
The following patch has been added/updated:

Patch Name: extend-error-msg.patch
Revision:   1328004117
URL:        https://bugs.php.net/patch-display.php?bug=60911&patch=extend-error-msg.patch&revision=1328004117
 [2012-01-31 10:05 UTC] [email protected]
I would still change the error message to include the hint to 'use'.
See attached patch.
 [2012-01-31 10:05 UTC] [email protected]
-Status: Wont fix +Status: Assigned -Assigned To: +Assigned To: gron
 [2012-03-04 18:33 UTC] [email protected]
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=323892
Log: Fixed Bug #60911 (Confusing error message when extending traits)
 [2012-03-04 18:33 UTC] [email protected]
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.


 [2012-03-04 18:33 UTC] [email protected]
-Status: Assigned +Status: Closed
 [2012-04-18 09:45 UTC] [email protected]
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0ed3b00406a4486635ce6086d9bb3ed585b89a1d
Log: Fixed Bug #60911 (Confusing error message when extending traits)
 [2012-07-24 23:36 UTC] [email protected]
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0ed3b00406a4486635ce6086d9bb3ed585b89a1d
Log: Fixed Bug #60911 (Confusing error message when extending traits)
 [2013-11-17 09:33 UTC] [email protected]
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0ed3b00406a4486635ce6086d9bb3ed585b89a1d
Log: Fixed Bug #60911 (Confusing error message when extending traits)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 01 07:00:03 2025 UTC