]> granicus.if.org Git - php/commitdiff
- MFH Constructors in interfaces
authorMarcus Boerger <helly@php.net>
Wed, 10 May 2006 01:23:55 +0000 (01:23 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 10 May 2006 01:23:55 +0000 (01:23 +0000)
Zend/zend_compile.c
tests/classes/ctor_in_interface_01.phpt [new file with mode: 0755]
tests/classes/ctor_in_interface_02.phpt [new file with mode: 0755]
tests/classes/ctor_in_interface_03.phpt [new file with mode: 0755]
tests/classes/ctor_in_interface_04.phpt [new file with mode: 0755]

index e6ccf2e3107321be042d86248325f6c02ecf866d..1330f295d023abc9a1de32b65f3d21e7ceb0fbc7 100644 (file)
@@ -1920,8 +1920,8 @@ static zend_bool zend_do_perform_implementation_check(zend_function *fe, zend_fu
                return 1;
        }
 
-       /* No implementation checks for constructors */
-       if (fe->common.fn_flags & ZEND_ACC_CTOR) {
+       /* Checks for constructors only if they are declared in an interface */
+       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 (executable)
index 0000000..f6f9b66
--- /dev/null
@@ -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 (executable)
index 0000000..a0dfe87
--- /dev/null
@@ -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 (executable)
index 0000000..953d682
--- /dev/null
@@ -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 (executable)
index 0000000..0016244
--- /dev/null
@@ -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