From a8bbc845514666b31e3cca1ff626182d08543af2 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 16 Oct 2024 18:58:42 +0200 Subject: [PATCH] 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. Closes GH-16462 --- NEWS | 2 ++ Zend/tests/asymmetric_visibility/static_props.phpt | 12 ++++++++++++ Zend/zend_compile.c | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 Zend/tests/asymmetric_visibility/static_props.phpt diff --git a/NEWS b/NEWS index 10864e4bfa9..c575af79139 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ PHP NEWS . Fixed bug GH-16168 (php 8.1 and earlier crash immediately when compiled with Xcode 16 clang on macOS 15). (nielsdos) . Fixed bug GH-16371 (Assertion failure in Zend/zend_weakrefs.c:646). (Arnaud) + . Fixed missing error when adding asymmetric visibility to static properties. + (ilutov) - Curl: . Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if diff --git a/Zend/tests/asymmetric_visibility/static_props.phpt b/Zend/tests/asymmetric_visibility/static_props.phpt new file mode 100644 index 00000000000..65fd3aa1923 --- /dev/null +++ b/Zend/tests/asymmetric_visibility/static_props.phpt @@ -0,0 +1,12 @@ +--TEST-- +Asymmetric visibility on static props +--FILE-- + +--EXPECTF-- +Fatal error: Static property may not have asymmetric visibility in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 99938df0c8f..ae50c29dffa 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -8598,6 +8598,10 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f zend_error_noreturn(E_COMPILE_ERROR, "Property cannot be both final and private"); } + if ((flags & ZEND_ACC_STATIC) && (flags & ZEND_ACC_PPP_SET_MASK)) { + zend_error_noreturn(E_COMPILE_ERROR, "Static property may not have asymmetric visibility"); + } + if (ce->ce_flags & ZEND_ACC_INTERFACE) { if (flags & ZEND_ACC_FINAL) { zend_error_noreturn(E_COMPILE_ERROR, "Property in interface cannot be final");