Skip to content

Commit b5f15ef

Browse files
author
Stefan Marr
committed
Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
1 parent 2e5d5e5 commit b5f15ef

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Zend/tests/traits/bug60145.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
3+
--FILE--
4+
<?php
5+
6+
trait foo {
7+
8+
}
9+
10+
interface MyInterface {
11+
use foo;
12+
13+
public function b();
14+
15+
}
16+
--EXPECTF--
17+
Fatal error: Cannot use traits inside of interfaces. foo is used in MyInterface in %s on line %d

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,6 +5023,12 @@ void zend_do_implements_interface(znode *interface_name TSRMLS_DC) /* {{{ */
50235023
void zend_do_implements_trait(znode *trait_name TSRMLS_DC) /* {{{ */
50245024
{
50255025
zend_op *opline;
5026+
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
5027+
zend_error(E_COMPILE_ERROR,
5028+
"Cannot use traits inside of interfaces. %s is used in %s",
5029+
Z_STRVAL(trait_name->u.constant), CG(active_class_entry)->name);
5030+
}
5031+
50265032

50275033
switch (zend_get_class_fetch_type(Z_STRVAL(trait_name->u.constant), Z_STRLEN(trait_name->u.constant))) {
50285034
case ZEND_FETCH_CLASS_SELF:

0 commit comments

Comments
 (0)