]> granicus.if.org Git - php/commitdiff
- Fix Bug #35720 A final constructor can be overwritten
authorMarcus Boerger <helly@php.net>
Sat, 17 Dec 2005 15:50:24 +0000 (15:50 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 17 Dec 2005 15:50:24 +0000 (15:50 +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 ff20c63625cfbf1eacf9a5dd2edacf4185057e75..8532fcb46f6397652e7a879e555c500cbe938dbd 100644 (file)
@@ -1941,6 +1941,12 @@ static void do_inherit_parent_constructor(zend_class_entry *ce TSRMLS_DC)
                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 %v::%v() with %v::%v()",
+                               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