|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 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) ; 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