Skip to content

Commit d51fb69

Browse files
Guilherme BlancoJulien Pauli
authored andcommitted
Removed parsing support traits to have extends and implements.
1 parent f48c232 commit d51fb69

File tree

4 files changed

+4
-16
lines changed

4 files changed

+4
-16
lines changed

Zend/tests/traits/bug55524.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ trait Foo extends Base {
1212
echo 'DONE';
1313
?>
1414
--EXPECTF--
15-
Fatal error: A trait (Foo) cannot extend a class. Traits can only be composed from other traits with the 'use' keyword. Error in %s on line %d
15+
Parse error: syntax error, unexpected 'extends' (T_EXTENDS), expecting '{' in %s on line %d

Zend/tests/traits/bugs/interfaces.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ trait THello implements MyInterface {
1616

1717
?>
1818
--EXPECTF--
19-
Fatal error: Cannot use 'MyInterface' as interface on 'THello' since it is a Trait in %s on line %d
19+
Parse error: syntax error, unexpected 'implements' (T_IMPLEMENTS), expecting '{' in %s on line %d

Zend/zend_compile.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,12 +4457,6 @@ void zend_compile_implements(znode *class_node, zend_ast *ast) /* {{{ */
44574457

44584458
zend_op *opline;
44594459

4460-
/* Traits can not implement interfaces */
4461-
if (ZEND_CE_IS_TRAIT(CG(active_class_entry))) {
4462-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as interface on '%s' "
4463-
"since it is a Trait", name->val, CG(active_class_entry)->name->val);
4464-
}
4465-
44664460
if (!zend_is_const_default_class_ref(class_ast)) {
44674461
zend_error_noreturn(E_COMPILE_ERROR,
44684462
"Cannot use '%s' as interface name as it is reserved", name->val);
@@ -4536,12 +4530,6 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
45364530
}
45374531

45384532
if (extends_ast) {
4539-
if (ZEND_CE_IS_TRAIT(ce)) {
4540-
zend_error_noreturn(E_COMPILE_ERROR, "A trait (%s) cannot extend a class. "
4541-
"Traits can only be composed from other traits with the 'use' keyword. Error",
4542-
name->val);
4543-
}
4544-
45454533
if (!zend_is_const_default_class_ref(extends_ast)) {
45464534
zend_string *extends_name = zend_ast_get_str(extends_ast);
45474535
zend_error_noreturn(E_COMPILE_ERROR,

Zend/zend_language_parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ class_modifier:
445445

446446
trait_declaration_statement:
447447
T_TRAIT { $<num>$ = CG(zend_lineno); }
448-
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
449-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8); }
448+
T_STRING backup_doc_comment '{' class_statement_list '}'
449+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6); }
450450
;
451451

452452
interface_declaration_statement:

0 commit comments

Comments
 (0)