Skip to content

Commit

Permalink
Added missing consistency check for abstract methods required by one …
Browse files Browse the repository at this point in the history
…trait and implemented by another.
  • Loading branch information
Stefan Marr committed Nov 1, 2011
1 parent ceac9dc commit 9b0d73a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Zend/tests/traits/bugs/abstract-methods05.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
The compatibility with the signature of abstract methods should be checked.
--FILE--
<?php
error_reporting(E_ALL);

trait THelloB {
public function hello() {
echo 'Hello';
}
}

trait THelloA {
public abstract function hello($a);
}

class TraitsTest1 {
use THelloB;
use THelloA;
}


?>
--EXPECTF--
Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d
26 changes: 26 additions & 0 deletions Zend/tests/traits/bugs/abstract-methods06.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
The compatibility with the signature of abstract methods should be checked. (also checking the second possible implementation branch)
--FILE--
<?php
error_reporting(E_ALL);

trait THelloB {
public function hello() {
echo 'Hello';
}
}

trait THelloA {
public abstract function hello($a);
}

class TraitsTest1 {
use THelloA;
use THelloB;
}



?>
--EXPECTF--
Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d
6 changes: 6 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3616,13 +3616,19 @@ static int zend_traits_merge_functions(zend_function *fn TSRMLS_DC, int num_args
if (zend_hash_quick_find(function_tables[i], hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **)&other_trait_fn) == SUCCESS) {
/* if it is an abstract method, there is no collision */
if (other_trait_fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
/* Make sure they are compatible */
do_inheritance_check_on_method(fn, other_trait_fn TSRMLS_CC);

/* we can savely free and remove it from other table */
zend_function_dtor(other_trait_fn);
zend_hash_quick_del(function_tables[i], hash_key->arKey, hash_key->nKeyLength, hash_key->h);
} else {
/* if it is not an abstract method, there is still no collision */
/* if fn is an abstract method */
if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
/* Make sure they are compatible */
do_inheritance_check_on_method(other_trait_fn, fn TSRMLS_CC);

/* just mark as solved, will be added if its own trait is processed */
abstract_solved = 1;
} else {
Expand Down

0 comments on commit 9b0d73a

Please sign in to comment.