|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69467 Wrong checked for the interface by using Trait
Submitted: 2015-04-16 08:42 UTC Modified: 2015-04-17 09:04 UTC
From: zeli dot box at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.4.39 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
21 - 1 = ?
Subscribe to this entry?

 [2015-04-16 08:42 UTC] zeli dot box at gmail dot com
Create an interface in the class:
1. Adding trait to the class
2. Implement interface methods in the trait, but making them private/protected
3. Create class object
4. Checking the object for the instance of interface returns true

This bug in php version > 5.4.10

But versions less than 5.4.10 was a fatal error:
"Fatal error:  Access level to Foo::bad() must be public (as in class Baz)"

Test script:
interface Baz {
    public function bad();

trait Bar{
    protected function bad(){}

class Foo implements Baz{
    use Bar;

$test = new Foo();
var_dump($test instanceof Baz);

Expected result:
Fatal error

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-16 09:18 UTC]
-Status: Open +Status: Verified
 [2015-04-16 09:18 UTC]

I can't bisect but the first place I would look for the change is
 [2015-04-17 09:04 UTC]
seems we are entering the looser check path. 

diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 4e61f5f..39bdfec 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3912,7 +3912,8 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, const
 			zend_hash_quick_update(*overriden, arKey, nKeyLength, h, fn, sizeof(zend_function), (void**)&fn)
-		} else if (existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
+		} else if (existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT
+				&& !(existing_fn->common.scope->ce_flags & ZEND_ACC_INTERFACE)) {
 			/* Make sure the trait method is compatible with previosly declared abstract method */
 			if (!zend_traits_method_compatibility_check(fn, existing_fn TSRMLS_CC)) {
 				zend_error(E_COMPILE_ERROR, "Declaration of %s must be compatible with %s",

 [2015-04-21 14:41 UTC]
Automatic comment on behalf of laruence
Log: Fixed Bug #69467 (Wrong checked for the interface by using Trait)
 [2015-04-21 14:41 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 11:01:31 2024 UTC