gron                                     Mon, 29 Aug 2011 15:53:46 +0000

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

Log:
Fixed bug #55524 Traits should not be able to extend a class
# also used the Z_STRVAL where it seemed appropriate

Bug: https://bugs.php.net/55524 (Assigned) Traits should not be able to extend 
a class
      
Changed paths:
    A   php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt
    U   php/php-src/branches/PHP_5_4/Zend/zend_compile.c
    A   php/php-src/trunk/Zend/tests/traits/bug55524.phpt
    U   php/php-src/trunk/Zend/zend_compile.c

Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt                
                (rev 0)
+++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug55524.phpt        
2011-08-29 15:53:46 UTC (rev 315712)
@@ -0,0 +1,15 @@
+--TEST--
+Bug #55524 Traits should not be able to extend a class
+--FILE--
+<?php
+
+class Base {}
+
+trait Foo extends Base {
+    function bar() {}
+}
+
+echo 'DONE';
+?>
+--EXPECTF--
+Fatal error: A trait (Foo) cannot extend a class in %s on line %d

Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/zend_compile.c    2011-08-29 15:44:23 UTC 
(rev 315711)
+++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c    2011-08-29 15:53:46 UTC 
(rev 315712)
@@ -4640,7 +4640,7 @@

        if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
                efree(lcname);
-               zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as 
it is reserved", class_name->u.constant.value.str.val);
+               zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as 
it is reserved", Z_STRVAL(class_name->u.constant));
        }

        /* Class name must not conflict with import names */
@@ -4707,6 +4707,11 @@
        opline->op2_type = IS_CONST;

        if (doing_inheritance) {
+       /* Make sure a trait does not try to extend a class */
+       if ((new_class_entry->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
+           zend_error(E_COMPILE_ERROR, "A trait (%s) cannot extend a class", 
new_class_entry->name);
+       }
+
                opline->extended_value = parent_class_name->u.op.var;
                opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
        } else {

Added: php/php-src/trunk/Zend/tests/traits/bug55524.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bug55524.phpt                           
(rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bug55524.phpt   2011-08-29 15:53:46 UTC 
(rev 315712)
@@ -0,0 +1,15 @@
+--TEST--
+Bug #55524 Traits should not be able to extend a class
+--FILE--
+<?php
+
+class Base {}
+
+trait Foo extends Base {
+    function bar() {}
+}
+
+echo 'DONE';
+?>
+--EXPECTF--
+Fatal error: A trait (Foo) cannot extend a class in %s on line %d

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2011-08-29 15:44:23 UTC (rev 
315711)
+++ php/php-src/trunk/Zend/zend_compile.c       2011-08-29 15:53:46 UTC (rev 
315712)
@@ -4640,7 +4640,7 @@

        if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
                efree(lcname);
-               zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as 
it is reserved", class_name->u.constant.value.str.val);
+               zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as 
it is reserved", Z_STRVAL(class_name->u.constant));
        }

        /* Class name must not conflict with import names */
@@ -4707,6 +4707,11 @@
        opline->op2_type = IS_CONST;

        if (doing_inheritance) {
+       /* Make sure a trait does not try to extend a class */
+       if ((new_class_entry->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
+           zend_error(E_COMPILE_ERROR, "A trait (%s) cannot extend a class", 
new_class_entry->name);
+       }
+
                opline->extended_value = parent_class_name->u.op.var;
                opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
        } else {

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

Reply via email to