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: davey@php.net Assigned: gron (profile)
Status: Closed Package: *General Issues
PHP Version: 5.4.0RC6 OS: OSX 10.7.2
Private report: No CVE-ID: None
 [2012-01-28 05:23 UTC] davey@php.net
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 gron@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-31 04:02 UTC] laruence@php.net
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] laruence@php.net
-Status: Open +Status: Wont fix -Type: Bug +Type: Feature/Change Request
 [2012-01-31 10:01 UTC] gron@php.net
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] gron@php.net
I would still change the error message to include the hint to 'use'.
See attached patch.
 [2012-01-31 10:05 UTC] gron@php.net
-Status: Wont fix +Status: Assigned -Assigned To: +Assigned To: gron
 [2012-03-04 18:33 UTC] gron@php.net
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] 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.


 [2012-03-04 18:33 UTC] gron@php.net
-Status: Assigned +Status: Closed
 [2012-04-18 09:45 UTC] laruence@php.net
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] rasmus@php.net
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] laruence@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC