diff options
| author | Marcus Boerger <helly@php.net> | 2005-12-17 15:50:24 +0000 |
|---|---|---|
| committer | Marcus Boerger <helly@php.net> | 2005-12-17 15:50:24 +0000 |
| commit | 170918c6eb8af7e96d4329bced2e40a6e339b13a (patch) | |
| tree | 3055e12b008d250577d9a261553783dfc8dd97de | |
| parent | 5d60cbc498b1e174273c918fc337a79fce968857 (diff) | |
| download | php-git-170918c6eb8af7e96d4329bced2e40a6e339b13a.tar.gz | |
- Fix Bug #35720 A final constructor can be overwritten
| -rw-r--r-- | Zend/zend_compile.c | 6 | ||||
| -rwxr-xr-x | tests/classes/final_ctor1.phpt | 29 | ||||
| -rwxr-xr-x | tests/classes/final_ctor2.phpt | 29 |
3 files changed, 64 insertions, 0 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ff20c63625..8532fcb46f 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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 index 0000000000..ebfa08081e --- /dev/null +++ b/tests/classes/final_ctor1.phpt @@ -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 index 0000000000..905337b408 --- /dev/null +++ b/tests/classes/final_ctor2.phpt @@ -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 |
