felipe                                   Tue, 04 May 2010 18:21:00 +0000

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

Log:
- Added check for abstract class

  abstract class foo { }
  class T { use foo; } // T cannot use foo - it is not a trait

- Added check for trait on NEW

  trait a { }
  new a; // Cannot instantiate trait a

# Tests for errors comming soon :)

Changed paths:
    U   php/php-src/trunk/Zend/zend_compile.c
    U   php/php-src/trunk/Zend/zend_vm_def.h
    U   php/php-src/trunk/Zend/zend_vm_execute.h

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2010-05-04 18:08:14 UTC (rev 
298985)
+++ php/php-src/trunk/Zend/zend_compile.c       2010-05-04 18:21:00 UTC (rev 
298986)
@@ -4518,7 +4518,7 @@
        opline->opcode = ZEND_ADD_TRAIT;
        SET_NODE(opline->op1, &CG(implementing_class));
        zend_resolve_class_name(trait_name, &opline->extended_value, 0 
TSRMLS_CC);
-       opline->extended_value = (opline->extended_value & 
~ZEND_FETCH_CLASS_MASK) | ZEND_FETCH_CLASS_TRAIT;
+       opline->extended_value = ZEND_FETCH_CLASS_TRAIT;
        opline->op2_type = IS_CONST;
        opline->op2.constant = zend_add_class_name_literal(CG(active_op_array), 
&trait_name->u.constant TSRMLS_CC);
        CG(active_class_entry)->num_traits++;

Modified: php/php-src/trunk/Zend/zend_vm_def.h
===================================================================
--- php/php-src/trunk/Zend/zend_vm_def.h        2010-05-04 18:08:14 UTC (rev 
298985)
+++ php/php-src/trunk/Zend/zend_vm_def.h        2010-05-04 18:21:00 UTC (rev 
298986)
@@ -3230,6 +3230,8 @@

                if (EX_T(opline->op1.var).class_entry->ce_flags & 
ZEND_ACC_INTERFACE) {
                        class_type = "interface";
+               } else if (EX_T(opline->op1.var).class_entry->ce_flags & 
ZEND_ACC_TRAIT) {
+                       class_type = "trait";
                } else {
                        class_type = "abstract class";
                }
@@ -4663,7 +4665,7 @@
                                              opline->extended_value TSRMLS_CC);

        if (trait) {
-               if (!(trait->ce_flags & ZEND_ACC_TRAIT)) {
+               if (!((trait->ce_flags & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) & 
ZEND_ACC_TRAIT)) {
                        zend_error_noreturn(E_ERROR, "%s cannot use %s - it is 
not a trait", ce->name, trait->name);
                }
                zend_do_implement_trait(ce, trait TSRMLS_CC);

Modified: php/php-src/trunk/Zend/zend_vm_execute.h
===================================================================
--- php/php-src/trunk/Zend/zend_vm_execute.h    2010-05-04 18:08:14 UTC (rev 
298985)
+++ php/php-src/trunk/Zend/zend_vm_execute.h    2010-05-04 18:21:00 UTC (rev 
298986)
@@ -520,6 +520,8 @@

                if (EX_T(opline->op1.var).class_entry->ce_flags & 
ZEND_ACC_INTERFACE) {
                        class_type = "interface";
+               } else if (EX_T(opline->op1.var).class_entry->ce_flags & 
ZEND_ACC_TRAIT) {
+                       class_type = "trait";
                } else {
                        class_type = "abstract class";
                }
@@ -691,7 +693,7 @@
                                              opline->extended_value TSRMLS_CC);

        if (trait) {
-               if (!(trait->ce_flags & ZEND_ACC_TRAIT)) {
+               if (!((trait->ce_flags & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) & 
ZEND_ACC_TRAIT)) {
                        zend_error_noreturn(E_ERROR, "%s cannot use %s - it is 
not a trait", ce->name, trait->name);
                }
                zend_do_implement_trait(ce, trait TSRMLS_CC);

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

Reply via email to