gron Tue, 01 Nov 2011 13:42:53 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=318646
Log:
Added missing consistency check for abstract methods required by one trait and
implemented by another.
Changed paths:
A
php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt
A
php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt
U php/php-src/branches/PHP_5_4/Zend/zend_compile.c
A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt
A php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt
U php/php-src/trunk/Zend/zend_compile.c
Added:
php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt
(rev 0)
+++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods05.phpt
2011-11-01 13:42:53 UTC (rev 318646)
@@ -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
\ No newline at end of file
Added:
php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt
(rev 0)
+++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bugs/abstract-methods06.phpt
2011-11-01 13:42:53 UTC (rev 318646)
@@ -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
\ No newline at end of file
Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-01 13:31:27 UTC
(rev 318645)
+++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2011-11-01 13:42:53 UTC
(rev 318646)
@@ -3616,6 +3616,9 @@
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);
@@ -3623,6 +3626,9 @@
/* 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 {
Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt
(rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods05.phpt
2011-11-01 13:42:53 UTC (rev 318646)
@@ -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
\ No newline at end of file
Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt
(rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods06.phpt
2011-11-01 13:42:53 UTC (rev 318646)
@@ -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
\ No newline at end of file
Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c 2011-11-01 13:31:27 UTC (rev
318645)
+++ php/php-src/trunk/Zend/zend_compile.c 2011-11-01 13:42:53 UTC (rev
318646)
@@ -3616,6 +3616,9 @@
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);
@@ -3623,6 +3626,9 @@
/* 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 {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php