Bug #69467 [Ver->Csd]: Wrong checked for the interface by using Trait

From: Date: Tue, 21 Apr 2015 14:41:47 +0000
Subject: Bug #69467 [Ver->Csd]: Wrong checked for the interface by using Trait
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192264@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69467&edit=1 ID: 69467 Updated by: laruence@php.net Reported by: zeli dot box at gmail dot com Summary: Wrong checked for the interface by using Trait -Status: Verified +Status: Closed Type: Bug Package: Class/Object related PHP Version: 5.4.39 Block user comment: N Private report: N New Comment: Automatic comment on behalf of laruence Revision: http://git.php.net/?p=php-src.git;a=commit;h=c667c26f616f91db5b890d39807c77c4720ba507 Log: Fixed Bug #69467 (Wrong checked for the interface by using Trait) Previous Comments: ------------------------------------------------------------------------ [2015-04-17 09:04:25] 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 ------------------------------------------------------------------------ [2015-04-16 09:18:13] requinix@php.net http://3v4l.org/p303Q I can't bisect but the first place I would look for the change is https://github.com/php/php-src/commit/3f8c729e693c432b438cd33679182260d8732e30 ------------------------------------------------------------------------ [2015-04-16 08:42:19] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69467&edit=1

« previous php.bugs (#192264) next »