php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60145 interface + use trait yields error for the abstract class?
Submitted: 2011-10-26 20:28 UTC Modified: 2011-11-01 00:40 UTC
From: ninzya at inbox dot lv Assigned: gron (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0beta2 OS: Any
Private report: No CVE-ID: None
 [2011-10-26 20:28 UTC] ninzya at inbox dot lv
Description:
------------
The code in the test script contains one trait and an interface, that uses this 
trait ("use TestTrait"). What I was trying to do here is to see how PHP behaves if 
i include "use" statement inside interface definition.

Suprisingly, test script produces very interesting result - I get a fatal error 
with the following text: "Class TestInterface contains 1 abstract method and must 
therefore be declared abstract or implement the remaining methods 
(TestInterface::b)". It looks like PHP's compiler messes up when I mix interfaces 
together with "use" statement and somehow treats "TestInterface" as an abstract 
class.

I didn't go deeper to look into the problem as it's pretty clear that something is 
wrong here. In my opinion, PHP should not allow usage of "use" statment inside 
interface defitions.

Test script:
---------------
trait TestTrait {

}

interface TestInterface {
	use TestTrait;

	public function b();

}

Expected result:
----------------
PHP Fatal error: use of "use" statement in interfaces is not allowed.

Actual result:
--------------
PHP Fatal error: Class TestInterface contains 1 abstract method and must therefore 
be declared abstract or implement the remaining methods (TestInterface::b).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-31 23:02 UTC] gron@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: gron
 [2011-11-01 00:39 UTC] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&revision=318625
Log: Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
 [2011-11-01 00:40 UTC] gron@php.net
-Status: Assigned +Status: Closed
 [2011-11-01 00:40 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 with SVN rev 318625.
 [2012-04-18 09:48 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3b74bba72423ddbf0bd7db1f708fc0961ea1c525
Log: Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
 [2012-07-24 23:39 UTC] rasmus@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3b74bba72423ddbf0bd7db1f708fc0961ea1c525
Log: Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
 [2013-11-17 09:35 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3b74bba72423ddbf0bd7db1f708fc0961ea1c525
Log: Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC