]> granicus.if.org Git - php/commitdiff
Fixed Bug #60145 (Usage of trait's use statement inside interfaces not properly checked.)
authorStefan Marr <gron@php.net>
Tue, 1 Nov 2011 00:39:10 +0000 (00:39 +0000)
committerStefan Marr <gron@php.net>
Tue, 1 Nov 2011 00:39:10 +0000 (00:39 +0000)
Zend/tests/traits/bug60145.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/traits/bug60145.phpt b/Zend/tests/traits/bug60145.phpt
new file mode 100644 (file)
index 0000000..fcd0cfa
--- /dev/null
@@ -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
index 47e6f5373683ec1dc4a5511808e45699ea484170..bf8a35d3ed96ba6cbf955fff9db4be376d0408f5 100644 (file)
@@ -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: