felipe                                   Fri, 07 May 2010 16:29:15 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299111

Log:
- Fixed ZEND_VERIFY_ABSTRACT_CLASS order when using traits
# It's the last one now, thus the traits can be used to implement interfaces

Changed paths:
    A   php/php-src/trunk/Zend/tests/traits/interface_001.phpt
    A   php/php-src/trunk/Zend/tests/traits/interface_002.phpt
    A   php/php-src/trunk/Zend/tests/traits/interface_003.phpt
    U   php/php-src/trunk/Zend/zend_compile.c

Added: php/php-src/trunk/Zend/tests/traits/interface_001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/interface_001.phpt                      
        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/interface_001.phpt      2010-05-07 
16:29:15 UTC (rev 299111)
@@ -0,0 +1,25 @@
+--TEST--
+Using traits to implement interface
+--FILE--
+<?php
+
+trait foo {
+       public function abc() {
+       }
+}
+
+interface baz {
+       public function abc();
+}
+
+class bar implements baz {
+       use foo;
+
+}
+
+new bar;
+print "OK\n";
+
+?>
+--EXPECT--
+OK


Property changes on: php/php-src/trunk/Zend/tests/traits/interface_001.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/trunk/Zend/tests/traits/interface_002.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/interface_002.phpt                      
        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/interface_002.phpt      2010-05-07 
16:29:15 UTC (rev 299111)
@@ -0,0 +1,24 @@
+--TEST--
+Checking error message when the trait doesn't implements the interface
+--FILE--
+<?php
+
+trait foo {
+       public function a() {
+       }
+}
+
+interface baz {
+       public function abc();
+}
+
+class bar implements baz {
+       use foo;
+
+}
+
+new bar;
+
+?>
+--EXPECTF--
+Fatal error: Class bar contains 1 abstract method and must therefore be 
declared abstract or implement the remaining methods (baz::abc) in %s on line %d


Property changes on: php/php-src/trunk/Zend/tests/traits/interface_002.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/trunk/Zend/tests/traits/interface_003.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/interface_003.phpt                      
        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/interface_003.phpt      2010-05-07 
16:29:15 UTC (rev 299111)
@@ -0,0 +1,27 @@
+--TEST--
+Testing to implement Serializable interface by traits
+--FILE--
+<?php
+
+trait foo {
+       public function serialize() {
+               return 'foobar';
+       }
+       public function unserialize($x) {
+               var_dump($x);
+       }
+}
+
+class bar implements Serializable {
+       use foo;
+}
+
+var_dump($o = serialize(new bar));
+var_dump(unserialize($o));
+
+?>
+--EXPECTF--
+string(20) "C:3:"bar":6:{foobar}"
+string(6) "foobar"
+object(bar)#%d (0) {
+}


Property changes on: php/php-src/trunk/Zend/tests/traits/interface_003.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2010-05-07 15:17:34 UTC (rev 
299110)
+++ php/php-src/trunk/Zend/zend_compile.c       2010-05-07 16:29:15 UTC (rev 
299111)
@@ -4461,7 +4461,23 @@
        }

        ce->line_end = zend_get_compiled_lineno(TSRMLS_C);
+
+       /* Check for traits and proceed like with interfaces.
+        * The only difference will be a combined handling of them in the end.
+        * Thus, we need another opcode here. */
+       if (ce->num_traits > 0) {
+               zend_op *opline;

+               ce->traits = NULL;
+               ce->num_traits = 0;
+               ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
+
+               /* opcode generation: */
+               opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+               opline->opcode = ZEND_BIND_TRAITS;
+               SET_NODE(opline->op1, &CG(implementing_class));
+       }
+
        if (!(ce->ce_flags & 
(ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
                && ((parent_token->op_type != IS_UNUSED) || (ce->num_interfaces 
> 0))) {
                zend_verify_abstract_class(ce TSRMLS_CC);
@@ -4479,22 +4495,6 @@
                ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
        }

-       /* Check for traits and proceed like with interfaces.
-        * The only difference will be a combined handling of them in the end.
-        * Thus, we need another opcode here. */
-       if (ce->num_traits > 0) {
-               zend_op *opline;
-
-               ce->traits = NULL;
-               ce->num_traits = 0;
-               ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
-
-               /* opcode generation: */
-               opline = get_next_op(CG(active_op_array) TSRMLS_CC);
-               opline->opcode = ZEND_BIND_TRAITS;
-               SET_NODE(opline->op1, &CG(implementing_class));
-       }
-
        CG(active_class_entry) = NULL;
 }
 /* }}} */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to