diff options
author | Marcus Boerger <helly@php.net> | 2006-03-05 18:23:56 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2006-03-05 18:23:56 +0000 |
commit | b0f461e9d9d63c81c07e257493e237df8bbee8c3 (patch) | |
tree | 1e88160d262b64852d79a76e1941d233fb67efe0 | |
parent | 05fa58f84e64b5c136bf0588703d951ad6325cc5 (diff) | |
download | php-git-b0f461e9d9d63c81c07e257493e237df8bbee8c3.tar.gz |
- Fix Bug #34019 by popular demand: Implementing interface with a
__construct method strange behaviour
-rw-r--r-- | Zend/zend_compile.c | 2 | ||||
-rwxr-xr-x | tests/classes/ctor_in_interface_01.phpt | 19 | ||||
-rwxr-xr-x | tests/classes/ctor_in_interface_02.phpt | 35 | ||||
-rwxr-xr-x | tests/classes/ctor_in_interface_03.phpt | 23 | ||||
-rwxr-xr-x | tests/classes/ctor_in_interface_04.phpt | 26 | ||||
-rwxr-xr-x | tests/classes/interface_construct.phpt | 24 |
6 files changed, 104 insertions, 25 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 08a90cc85a..09eb3212a0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2055,7 +2055,7 @@ static zend_bool zend_do_perform_implementation_check(zend_function *fe, zend_fu } /* No implementation checks for constructors */ - if (fe->common.fn_flags & ZEND_ACC_CTOR) { + if ((fe->common.fn_flags & ZEND_ACC_CTOR) && !(proto->common.scope->ce_flags & ZEND_ACC_INTERFACE)) { return 1; } diff --git a/tests/classes/ctor_in_interface_01.phpt b/tests/classes/ctor_in_interface_01.phpt new file mode 100755 index 0000000000..f6f9b66eab --- /dev/null +++ b/tests/classes/ctor_in_interface_01.phpt @@ -0,0 +1,19 @@ +--TEST-- +ZE2 A class constructor must keep the signature of an interface +--FILE-- +<?php +interface constr +{ + function __construct(); +} + +class implem implements constr +{ + function __construct($a) + { + } +} + +?> +--EXPECTF-- +Fatal error: Declaration of implem::__construct() must be compatible with that of constr::__construct() in %s on line %d diff --git a/tests/classes/ctor_in_interface_02.phpt b/tests/classes/ctor_in_interface_02.phpt new file mode 100755 index 0000000000..a0dfe87788 --- /dev/null +++ b/tests/classes/ctor_in_interface_02.phpt @@ -0,0 +1,35 @@ +--TEST-- +ZE2 A class constructor must keep the signature of all interfaces +--FILE-- +<?php +interface constr1 +{ + function __construct(); +} + +interface constr2 extends constr1 +{ +} + +class implem12 implements constr2 +{ + function __construct() + { + } +} + +interface constr3 +{ + function __construct($a); +} + +class implem13 implements constr1, constr3 +{ + function __construct() + { + } +} + +?> +--EXPECTF-- +Fatal error: Can't inherit abstract function constr3::__construct() (previously declared abstract in constr1) in %s on line %d diff --git a/tests/classes/ctor_in_interface_03.phpt b/tests/classes/ctor_in_interface_03.phpt new file mode 100755 index 0000000000..953d6822fd --- /dev/null +++ b/tests/classes/ctor_in_interface_03.phpt @@ -0,0 +1,23 @@ +--TEST-- +ZE2 A class constructor must keep the signature of base class interfaces +--FILE-- +<?php +interface constr +{ + function __construct(); +} + +abstract class implem implements constr +{ +} + +class derived extends implem +{ + function __construct($a) + { + } +} + +?> +--EXPECTF-- +Fatal error: Declaration of derived::__construct() must be compatible with that of constr::__construct() in %s on line %d diff --git a/tests/classes/ctor_in_interface_04.phpt b/tests/classes/ctor_in_interface_04.phpt new file mode 100755 index 0000000000..0016244c18 --- /dev/null +++ b/tests/classes/ctor_in_interface_04.phpt @@ -0,0 +1,26 @@ +--TEST-- +ZE2 A class constructor must keep the signature of base class interfaces +--FILE-- +<?php +interface constr +{ + function __construct(); +} + +class implem implements constr +{ + function __construct() + { + } +} + +class derived extends implem +{ + function __construct($a) + { + } +} + +?> +--EXPECTF-- +Fatal error: Declaration of derived::__construct() must be compatible with that of constr::__construct() in %s on line %d diff --git a/tests/classes/interface_construct.phpt b/tests/classes/interface_construct.phpt deleted file mode 100755 index 406462e17a..0000000000 --- a/tests/classes/interface_construct.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -ZE2 An interface constructor signature must not be inherited ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php -error_reporting(4095); - -interface test { - public function __construct($foo); -} - -class foo implements test { - public function __construct() { - echo "foo\n"; - } -} - -$foo = new foo; - -?> ---EXPECT-- -foo - |