Skip to content

Commit ba64dba

Browse files
committed
Improve readonly avis error
We don't track whether protected(set) is implicit, so for now always point out when the property is readonly in the error message.
1 parent 4f6f4fb commit ba64dba

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

Zend/tests/asymmetric_visibility/readonly.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ test();
5757
?>
5858
--EXPECT--
5959
Cannot modify private(set) property P::$pPrivate from scope C
60-
Cannot modify protected(set) property P::$pDefault from global scope
60+
Cannot modify protected(set) readonly property P::$pDefault from global scope
6161
Cannot modify private(set) property P::$pPrivate from global scope
62-
Cannot modify protected(set) property P::$pProtected from global scope
62+
Cannot modify protected(set) readonly property P::$pProtected from global scope

Zend/tests/readonly_props/initialization_scope.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var_dump($test);
5959

6060
?>
6161
--EXPECTF--
62-
Cannot modify protected(set) property A::$prop from global scope
62+
Cannot modify protected(set) readonly property A::$prop from global scope
6363
object(B)#%d (1) {
6464
["prop"]=>
6565
int(2)

Zend/tests/readonly_props/magic_get_set.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ try {
6464
--EXPECT--
6565
bool(false)
6666
Typed property Test::$prop must not be accessed before initialization
67-
Cannot modify protected(set) property Test::$prop from global scope
68-
Cannot unset protected(set) property Test::$prop from global scope
67+
Cannot modify protected(set) readonly property Test::$prop from global scope
68+
Cannot unset protected(set) readonly property Test::$prop from global scope
6969
Test::__isset(prop)
7070
bool(true)
7171
Test::__get(prop)

Zend/tests/readonly_props/unset.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ Test2::__get
6161
int(1)
6262
int(1)
6363
Cannot unset readonly property Test2::$prop
64-
Cannot unset protected(set) property Test3::$prop from global scope
64+
Cannot unset protected(set) readonly property Test3::$prop from global scope

Zend/tests/readonly_props/variation.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ Init: 0, scope: 1, op: is: 0
126126
Init: 0, scope: 1, op: us: done
127127
Init: 0, scope: 1, op: us_dim: done
128128
Init: 0, scope: 0, op: r: Typed property Test::$prop must not be accessed before initialization
129-
Init: 0, scope: 0, op: w: Cannot modify protected(set) property Test::$prop from global scope
129+
Init: 0, scope: 0, op: w: Cannot modify protected(set) readonly property Test::$prop from global scope
130130
Init: 0, scope: 0, op: rw: Typed property Test::$prop must not be accessed before initialization
131131
Init: 0, scope: 0, op: im: Cannot indirectly modify readonly property Test::$prop
132132
Init: 0, scope: 0, op: is: 0
133-
Init: 0, scope: 0, op: us: Cannot unset protected(set) property Test::$prop from global scope
133+
Init: 0, scope: 0, op: us: Cannot unset protected(set) readonly property Test::$prop from global scope
134134
Init: 0, scope: 0, op: us_dim: done

Zend/zend_execute.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,11 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modifi
930930
visibility = "private(set)";
931931
} else {
932932
ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET);
933-
visibility = "protected(set)";
933+
if (prop_info->flags & ZEND_ACC_READONLY) {
934+
visibility = "protected(set) readonly";
935+
} else {
936+
visibility = "protected(set)";
937+
}
934938
}
935939

936940
zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s",

0 commit comments

Comments
 (0)