- Fix Bug #35720 A final constructor can be overwritten

This commit is contained in:
Marcus Boerger 2005-12-17 15:50:24 +00:00
parent 5d60cbc498
commit 170918c6eb
3 changed files with 64 additions and 0 deletions

View file

@ -1941,6 +1941,12 @@ static void do_inherit_parent_constructor(zend_class_entry *ce TSRMLS_DC)
ce->destructor = ce->parent->destructor; ce->destructor = ce->parent->destructor;
} }
if (ce->constructor) { 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; return;
} }

29
tests/classes/final_ctor1.phpt Executable file
View file

@ -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

29
tests/classes/final_ctor2.phpt Executable file
View file

@ -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