Wrong checked for the interface by using Trait
| 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 | ||
[2015-04-16 08:42 UTC] zeli dot box at gmail dot com
Description:
------------
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:
--------------
bool(true)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2015-04-17 09:04 UTC] laruence@php.net
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) ; return; - } 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", thanks