Skip to content

Commit 65ba36a

Browse files
committed
Disallow asymmetric visibility on static properties
This check was forgotten in the original implementation. Relaxing this restriction shouldn't be hard, but needs some work. We either need to prevent merging of cache slots for R/RW/W, or we need to introduce an additional check when writing to the property indirectly. This check is currently present only for direct writes.
1 parent 8aa3260 commit 65ba36a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Asymmetric visibility on static props
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public private(set) static int $prop;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Static property may not have asymmetric visibility in %s on line %d

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8598,6 +8598,10 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
85988598
zend_error_noreturn(E_COMPILE_ERROR, "Property cannot be both final and private");
85998599
}
86008600

8601+
if ((flags & ZEND_ACC_STATIC) && (flags & ZEND_ACC_PPP_SET_MASK)) {
8602+
zend_error_noreturn(E_COMPILE_ERROR, "Static property may not have asymmetric visibility");
8603+
}
8604+
86018605
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
86028606
if (flags & ZEND_ACC_FINAL) {
86038607
zend_error_noreturn(E_COMPILE_ERROR, "Property in interface cannot be final");

0 commit comments

Comments
 (0)