Browse Source

MFH: disallow multiple access modifiers and 'abstract abstract' methods (patch by Etienne Kneuss)

add tests
PECL
Antony Dovgal 19 years ago
parent
commit
714aad97e7
  1. 14
      Zend/tests/access_modifiers_001.phpt
  2. 13
      Zend/tests/access_modifiers_002.phpt
  3. 13
      Zend/tests/access_modifiers_003.phpt
  4. 14
      Zend/tests/access_modifiers_004.phpt
  5. 14
      Zend/tests/access_modifiers_005.phpt
  6. 14
      Zend/tests/access_modifiers_006.phpt
  7. 13
      Zend/tests/access_modifiers_007.phpt
  8. 15
      Zend/zend_compile.c

14
Zend/tests/access_modifiers_001.phpt

@ -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

13
Zend/tests/access_modifiers_002.phpt

@ -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

13
Zend/tests/access_modifiers_003.phpt

@ -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

14
Zend/tests/access_modifiers_004.phpt

@ -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

14
Zend/tests/access_modifiers_005.phpt

@ -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

14
Zend/tests/access_modifiers_006.phpt

@ -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

13
Zend/tests/access_modifiers_007.phpt

@ -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

15
Zend/zend_compile.c

@ -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");
}

Loading…
Cancel
Save