]> granicus.if.org Git - php/commitdiff
MFH: disallow multiple access modifiers and 'abstract abstract' methods (patch by...
authorAntony Dovgal <tony2001@php.net>
Tue, 13 Nov 2007 16:52:14 +0000 (16:52 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 13 Nov 2007 16:52:14 +0000 (16:52 +0000)
add tests

Zend/tests/access_modifiers_001.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_002.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_003.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_004.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_005.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_006.phpt [new file with mode: 0644]
Zend/tests/access_modifiers_007.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/access_modifiers_001.phpt b/Zend/tests/access_modifiers_001.phpt
new file mode 100644 (file)
index 0000000..989b926
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+using multiple access modifiers (methods)
+--FILE--
+<?php
+
+class test {
+       static public public static final public final function foo() {
+       }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Multiple access type modifiers are not allowed in %s on line %d
diff --git a/Zend/tests/access_modifiers_002.phpt b/Zend/tests/access_modifiers_002.phpt
new file mode 100644 (file)
index 0000000..cc5df30
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+using multiple access modifiers (attributes)
+--FILE--
+<?php
+
+class test {
+       static public public static final public final $var;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Multiple access type modifiers are not allowed in %s on line %d
diff --git a/Zend/tests/access_modifiers_003.phpt b/Zend/tests/access_modifiers_003.phpt
new file mode 100644 (file)
index 0000000..9c5a20a
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+using multiple access modifiers (classes)
+--FILE--
+<?php
+
+final final class test {
+       function foo() {}
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Parse error: syntax error, unexpected T_FINAL, expecting T_CLASS in %s on line %d
diff --git a/Zend/tests/access_modifiers_004.phpt b/Zend/tests/access_modifiers_004.phpt
new file mode 100644 (file)
index 0000000..c023d2c
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+using multiple access modifiers (abstract methods)
+--FILE--
+<?php
+
+class test {
+       abstract abstract function foo() {
+       }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Multiple abstract modifiers are not allowed in %s on line %d
diff --git a/Zend/tests/access_modifiers_005.phpt b/Zend/tests/access_modifiers_005.phpt
new file mode 100644 (file)
index 0000000..b32394d
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+using multiple access modifiers (final methods)
+--FILE--
+<?php
+
+class test {
+       final final function foo() {
+       }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Multiple final modifiers are not allowed in %s on line %d
diff --git a/Zend/tests/access_modifiers_006.phpt b/Zend/tests/access_modifiers_006.phpt
new file mode 100644 (file)
index 0000000..293fc1c
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+using multiple access modifiers (static methods)
+--FILE--
+<?php
+
+class test {
+       static static function foo() {
+       }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Multiple static modifiers are not allowed in %s on line %d
diff --git a/Zend/tests/access_modifiers_007.phpt b/Zend/tests/access_modifiers_007.phpt
new file mode 100644 (file)
index 0000000..26779e6
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+abstract final methods errmsg
+--FILE--
+<?php
+
+class test {
+       final abstract function foo();
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Fatal error: Cannot use the final modifier on an abstract class member in %s on line %d
index a16ec289cb7d152ee348283c1a68b3ed7399b993..36c9fa6be2d3c41c7303919ddefd16f20286d8e5 100644 (file)
@@ -1057,10 +1057,21 @@ void zend_do_free(znode *op1 TSRMLS_DC)
 int zend_do_verify_access_types(znode *current_access_type, znode *new_modifier)
 {
        if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_PPP_MASK)
-               && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK)
-               && ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_PPP_MASK) != (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK))) {
+               && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK)) {
                zend_error(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed");
        }
+       if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_ABSTRACT)
+               && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_ABSTRACT)) {
+               zend_error(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
+       }
+       if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_STATIC)
+               && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_STATIC)) {
+               zend_error(E_COMPILE_ERROR, "Multiple static modifiers are not allowed");
+       }
+       if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_FINAL)
+               && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_FINAL)) {
+               zend_error(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
+       }
        if (((Z_LVAL(current_access_type->u.constant) | Z_LVAL(new_modifier->u.constant)) & (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) == (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) {
                zend_error(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
        }