From daeb3295b2186782a610d1d21ed9364d7b5abc89 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 28 Aug 2024 15:17:57 +0200 Subject: [PATCH] Improve readonly avis error (GH-15618) We don't track whether protected(set) is implicit, so for now always point out when the property is readonly in the error message. --- Zend/tests/asymmetric_visibility/readonly.phpt | 4 ++-- Zend/tests/readonly_props/initialization_scope.phpt | 2 +- Zend/tests/readonly_props/magic_get_set.phpt | 4 ++-- Zend/tests/readonly_props/unset.phpt | 2 +- Zend/tests/readonly_props/variation.phpt | 4 ++-- Zend/zend_execute.c | 6 +++++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Zend/tests/asymmetric_visibility/readonly.phpt b/Zend/tests/asymmetric_visibility/readonly.phpt index 8fa77aafb1d9..e02d36907998 100644 --- a/Zend/tests/asymmetric_visibility/readonly.phpt +++ b/Zend/tests/asymmetric_visibility/readonly.phpt @@ -57,6 +57,6 @@ test(); ?> --EXPECT-- Cannot modify private(set) property P::$pPrivate from scope C -Cannot modify protected(set) property P::$pDefault from global scope +Cannot modify protected(set) readonly property P::$pDefault from global scope Cannot modify private(set) property P::$pPrivate from global scope -Cannot modify protected(set) property P::$pProtected from global scope +Cannot modify protected(set) readonly property P::$pProtected from global scope diff --git a/Zend/tests/readonly_props/initialization_scope.phpt b/Zend/tests/readonly_props/initialization_scope.phpt index f3e87efb2dfa..49a4341e138f 100644 --- a/Zend/tests/readonly_props/initialization_scope.phpt +++ b/Zend/tests/readonly_props/initialization_scope.phpt @@ -59,7 +59,7 @@ var_dump($test); ?> --EXPECTF-- -Cannot modify protected(set) property A::$prop from global scope +Cannot modify protected(set) readonly property A::$prop from global scope object(B)#%d (1) { ["prop"]=> int(2) diff --git a/Zend/tests/readonly_props/magic_get_set.phpt b/Zend/tests/readonly_props/magic_get_set.phpt index 2ce24cf2f111..ff9d7c7e3325 100644 --- a/Zend/tests/readonly_props/magic_get_set.phpt +++ b/Zend/tests/readonly_props/magic_get_set.phpt @@ -64,8 +64,8 @@ try { --EXPECT-- bool(false) Typed property Test::$prop must not be accessed before initialization -Cannot modify protected(set) property Test::$prop from global scope -Cannot unset protected(set) property Test::$prop from global scope +Cannot modify protected(set) readonly property Test::$prop from global scope +Cannot unset protected(set) readonly property Test::$prop from global scope Test::__isset(prop) bool(true) Test::__get(prop) diff --git a/Zend/tests/readonly_props/unset.phpt b/Zend/tests/readonly_props/unset.phpt index d6c3f1edf547..b8bd4218fa0c 100644 --- a/Zend/tests/readonly_props/unset.phpt +++ b/Zend/tests/readonly_props/unset.phpt @@ -61,4 +61,4 @@ Test2::__get int(1) int(1) Cannot unset readonly property Test2::$prop -Cannot unset protected(set) property Test3::$prop from global scope +Cannot unset protected(set) readonly property Test3::$prop from global scope diff --git a/Zend/tests/readonly_props/variation.phpt b/Zend/tests/readonly_props/variation.phpt index 12d4b41ed9fc..420eec8705dc 100644 --- a/Zend/tests/readonly_props/variation.phpt +++ b/Zend/tests/readonly_props/variation.phpt @@ -126,9 +126,9 @@ Init: 0, scope: 1, op: is: 0 Init: 0, scope: 1, op: us: done Init: 0, scope: 1, op: us_dim: done Init: 0, scope: 0, op: r: Typed property Test::$prop must not be accessed before initialization -Init: 0, scope: 0, op: w: Cannot modify protected(set) property Test::$prop from global scope +Init: 0, scope: 0, op: w: Cannot modify protected(set) readonly property Test::$prop from global scope Init: 0, scope: 0, op: rw: Typed property Test::$prop must not be accessed before initialization Init: 0, scope: 0, op: im: Cannot indirectly modify readonly property Test::$prop Init: 0, scope: 0, op: is: 0 -Init: 0, scope: 0, op: us: Cannot unset protected(set) property Test::$prop from global scope +Init: 0, scope: 0, op: us: Cannot unset protected(set) readonly property Test::$prop from global scope Init: 0, scope: 0, op: us_dim: done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 95fa9f1c01a1..733ce54dc24a 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -930,7 +930,11 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modifi visibility = "private(set)"; } else { ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET); - visibility = "protected(set)"; + if (prop_info->flags & ZEND_ACC_READONLY) { + visibility = "protected(set) readonly"; + } else { + visibility = "protected(set)"; + } } zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s",