diff options
| author | Stefan Marr <gron@php.net> | 2011-08-29 15:53:46 +0000 |
|---|---|---|
| committer | Stefan Marr <gron@php.net> | 2011-08-29 15:53:46 +0000 |
| commit | 1f4dfded592909a162f4b590a25edc681e6b338d (patch) | |
| tree | 1e8cdf35c37f461da08942ce0a3850d52c91e71f | |
| parent | a1501cf142381d6e1e9a285efd3cccdde5749357 (diff) | |
| download | php-git-1f4dfded592909a162f4b590a25edc681e6b338d.tar.gz | |
Fixed bug #55524 Traits should not be able to extend a class
# also used the Z_STRVAL where it seemed appropriate
| -rw-r--r-- | Zend/tests/traits/bug55524.phpt | 15 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 7 |
2 files changed, 21 insertions, 1 deletions
diff --git a/Zend/tests/traits/bug55524.phpt b/Zend/tests/traits/bug55524.phpt new file mode 100644 index 0000000000..1911cde130 --- /dev/null +++ b/Zend/tests/traits/bug55524.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #55524 Traits should not be able to extend a class +--FILE-- +<?php + +class Base {} + +trait Foo extends Base { + function bar() {} +} + +echo 'DONE'; +?> +--EXPECTF-- +Fatal error: A trait (Foo) cannot extend a class in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 9e673b854d..000942f9df 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4640,7 +4640,7 @@ void zend_do_begin_class_declaration(const znode *class_token, znode *class_name if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) { efree(lcname); - zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", class_name->u.constant.value.str.val); + zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", Z_STRVAL(class_name->u.constant)); } /* Class name must not conflict with import names */ @@ -4707,6 +4707,11 @@ void zend_do_begin_class_declaration(const znode *class_token, znode *class_name opline->op2_type = IS_CONST; if (doing_inheritance) { + /* Make sure a trait does not try to extend a class */ + if ((new_class_entry->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { + zend_error(E_COMPILE_ERROR, "A trait (%s) cannot extend a class", new_class_entry->name); + } + opline->extended_value = parent_class_name->u.op.var; opline->opcode = ZEND_DECLARE_INHERITED_CLASS; } else { |
