summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/tests/traits/bug60145.phpt17
-rw-r--r--Zend/zend_compile.c6
2 files changed, 23 insertions, 0 deletions
diff --git a/Zend/tests/traits/bug60145.phpt b/Zend/tests/traits/bug60145.phpt
new file mode 100644
index 0000000000..fcd0cfa5f2
--- /dev/null
+++ b/Zend/tests/traits/bug60145.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
+--FILE--
+<?php
+
+trait foo {
+
+}
+
+interface MyInterface {
+ use foo;
+
+ public function b();
+
+}
+--EXPECTF--
+Fatal error: Cannot use traits inside of interfaces. foo is used in MyInterface in %s on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 47e6f53736..bf8a35d3ed 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5023,6 +5023,12 @@ void zend_do_implements_interface(znode *interface_name TSRMLS_DC) /* {{{ */
void zend_do_implements_trait(znode *trait_name TSRMLS_DC) /* {{{ */
{
zend_op *opline;
+ if ((CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
+ zend_error(E_COMPILE_ERROR,
+ "Cannot use traits inside of interfaces. %s is used in %s",
+ Z_STRVAL(trait_name->u.constant), CG(active_class_entry)->name);
+ }
+
switch (zend_get_class_fetch_type(Z_STRVAL(trait_name->u.constant), Z_STRLEN(trait_name->u.constant))) {
case ZEND_FETCH_CLASS_SELF: