mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Check interface/trait extension for internal classes
Removed possibility to have extensions to declare classes extending interfaces or traits. It was checked in user classes, not extensions or internal.
This commit is contained in:
parent
c17e007a29
commit
4498d34aea
2 changed files with 18 additions and 12 deletions
|
@ -767,15 +767,27 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
|
|||
zend_string *key;
|
||||
zval *zv;
|
||||
|
||||
if ((ce->ce_flags & ZEND_ACC_INTERFACE)
|
||||
&& !(parent_ce->ce_flags & ZEND_ACC_INTERFACE)) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Interface %s may not inherit from class (%s)", ce->name->val, parent_ce->name->val);
|
||||
}
|
||||
if (parent_ce->ce_flags & ZEND_ACC_FINAL) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Class %s may not inherit from final class (%s)", ce->name->val, parent_ce->name->val);
|
||||
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
|
||||
/* Interface can only inherit other interfaces */
|
||||
if (!(parent_ce->ce_flags & ZEND_ACC_INTERFACE)) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Interface %s may not inherit from class (%s)", ce->name->val, parent_ce->name->val);
|
||||
}
|
||||
} else {
|
||||
/* Class declaration must not extend traits or interfaces */
|
||||
if (parent_ce->ce_flags & ZEND_ACC_INTERFACE) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend from interface %s", ce->name->val, parent_ce->name->val);
|
||||
} else if (parent_ce->ce_flags & ZEND_ACC_TRAIT) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend from trait %s", ce->name->val, parent_ce->name->val);
|
||||
}
|
||||
|
||||
/* Class must not extend a final class */
|
||||
if (parent_ce->ce_flags & ZEND_ACC_FINAL) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Class %s may not inherit from final class (%s)", ce->name->val, parent_ce->name->val);
|
||||
}
|
||||
}
|
||||
|
||||
ce->parent = parent_ce;
|
||||
|
||||
/* Copy serialize/unserialize callbacks */
|
||||
if (!ce->serialize) {
|
||||
ce->serialize = parent_ce->serialize;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue