]> granicus.if.org Git - php/commitdiff
- MFH Fix Bug #35720 A final constructor can be overwritten
authorMarcus Boerger <helly@php.net>
Sat, 17 Dec 2005 15:51:52 +0000 (15:51 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 17 Dec 2005 15:51:52 +0000 (15:51 +0000)
Zend/zend_compile.c
tests/classes/final_ctor1.phpt [new file with mode: 0755]
tests/classes/final_ctor2.phpt [new file with mode: 0755]

index f9257698fd98baffaaf61280823b2e3f09643ad8..b8153857e7110b4a30ca91388463665c79a9c74b 100644 (file)
@@ -1841,6 +1841,12 @@ static void do_inherit_parent_constructor(zend_class_entry *ce)
                ce->destructor   = ce->parent->destructor;
        }
        if (ce->constructor) {
+               if (ce->parent->constructor && ce->parent->constructor->common.fn_flags & ZEND_ACC_FINAL) {
+                       zend_error(E_ERROR, "Cannot override final %s::%s() with %s::%s()",
+                               ce->parent->name, ce->parent->constructor->common.function_name,
+                               ce->name, ce->constructor->common.function_name
+                               );
+               }
                return;
        }
        
diff --git a/tests/classes/final_ctor1.phpt b/tests/classes/final_ctor1.phpt
new file mode 100755 (executable)
index 0000000..ebfa080
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+ZE2 cannot override final __construct
+--FILE--
+<?php
+
+class Base
+{
+       public final function __construct()
+       {
+       }
+}
+
+class Works extends Base
+{
+}
+
+class Extended extends Base
+{
+       public function Extended()
+       {
+       }
+}
+
+ReflectionClass::export('Extended');
+
+?>
+--EXPECTF--
+
+Fatal error: Cannot override final Base::__construct() with Extended::Extended() in %sfinal_ctor1.php on line %d
diff --git a/tests/classes/final_ctor2.phpt b/tests/classes/final_ctor2.phpt
new file mode 100755 (executable)
index 0000000..905337b
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+ZE2 cannot override final old style ctor
+--FILE--
+<?php
+
+class Base
+{
+       public final function Base()
+       {
+       }
+}
+
+class Works extends Base
+{
+}
+
+class Extended extends Base
+{
+       public function __construct()
+       {
+       }
+}
+
+ReflectionClass::export('Extended');
+
+?>
+--EXPECTF--
+
+Fatal error: Cannot override final Base::Base() with Extended::__construct() in %sfinal_ctor2.php on line %d