Skip to content

Commit 21f7dfc

Browse files
committed
do not allow private/protected classes on interfaces
1 parent 10b2f63 commit 21f7dfc

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9196,6 +9196,12 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
91969196
int propFlags = decl->attr & ZEND_ACC_PPP_MASK;
91979197
decl->attr &= ~(ZEND_ACC_PPP_MASK | ZEND_ACC_FINAL | ZEND_ACC_READONLY | ZEND_ACC_ABSTRACT);
91989198

9199+
if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE && propFlags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
9200+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s::$%s as %s in interface %s",
9201+
ZSTR_VAL(CG(active_class_entry)->name), ZSTR_VAL(unqualified_name),
9202+
zend_visibility_string(propFlags), ZSTR_VAL(CG(active_class_entry)->name));
9203+
}
9204+
91999205
ce->required_scope = propFlags & (ZEND_ACC_PRIVATE | ZEND_ACC_PROTECTED) ? CG(active_class_entry) : NULL;
92009206
ce->required_scope_absolute = propFlags & ZEND_ACC_PRIVATE ? true : false;
92019207
ce->lexical_scope = CG(active_class_entry);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
usage in an interface
3+
--FILE--
4+
<?php
5+
6+
interface Outer {
7+
protected class Inner {}
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Cannot declare Outer::$Inner as protected in interface Outer in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
usage in an interface
3+
--FILE--
4+
<?php
5+
6+
interface Outer {
7+
private class Inner {}
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Cannot declare Outer::$Inner as private in interface Outer in %s on line %d

0 commit comments

Comments
 (0)