mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
- Fix Bug #35720 A final constructor can be overwritten
This commit is contained in:
parent
5d60cbc498
commit
170918c6eb
3 changed files with 64 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
29
tests/classes/final_ctor1.phpt
Executable file
29
tests/classes/final_ctor1.phpt
Executable 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
29
tests/classes/final_ctor2.phpt
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue