From 6312eedb4c9fcdf5b4881552e8de2651f519dd23 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Mon, 22 Sep 2025 12:42:56 +0200 Subject: [PATCH] Tweak get/set-only hook error messages Fixes GH-19845 --- Zend/tests/asymmetric_visibility/virtual_get_only.phpt | 2 +- Zend/tests/asymmetric_visibility/virtual_set_only.phpt | 2 +- Zend/tests/property_hooks/bug001.phpt | 2 +- Zend/tests/property_hooks/bug008.phpt | 2 +- Zend/tests/property_hooks/get.phpt | 2 +- Zend/tests/property_hooks/override_add_get.phpt | 2 +- Zend/tests/property_hooks/override_add_set.phpt | 2 +- Zend/tests/property_hooks/set.phpt | 4 ++-- Zend/tests/property_hooks/type_compatibility.phpt | 2 +- Zend/tests/property_hooks/type_compatibility_invalid.phpt | 2 +- Zend/zend_inheritance.c | 2 +- Zend/zend_object_handlers.c | 6 +++--- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Zend/tests/asymmetric_visibility/virtual_get_only.phpt b/Zend/tests/asymmetric_visibility/virtual_get_only.phpt index 3eaada70329d4..a3f6f980bdfe3 100644 --- a/Zend/tests/asymmetric_visibility/virtual_get_only.phpt +++ b/Zend/tests/asymmetric_visibility/virtual_get_only.phpt @@ -11,4 +11,4 @@ class Foo { ?> --EXPECTF-- -Fatal error: Read-only virtual property Foo::$bar must not specify asymmetric visibility in %s on line %d +Fatal error: get-only virtual property Foo::$bar must not specify asymmetric visibility in %s on line %d diff --git a/Zend/tests/asymmetric_visibility/virtual_set_only.phpt b/Zend/tests/asymmetric_visibility/virtual_set_only.phpt index 18abb7ac046a4..7d1d2bc7cb99f 100644 --- a/Zend/tests/asymmetric_visibility/virtual_set_only.phpt +++ b/Zend/tests/asymmetric_visibility/virtual_set_only.phpt @@ -11,4 +11,4 @@ class Foo { ?> --EXPECTF-- -Fatal error: Write-only virtual property Foo::$bar must not specify asymmetric visibility in %s on line %d +Fatal error: set-only virtual property Foo::$bar must not specify asymmetric visibility in %s on line %d diff --git a/Zend/tests/property_hooks/bug001.phpt b/Zend/tests/property_hooks/bug001.phpt index 5328506d476cb..62291019b3338 100644 --- a/Zend/tests/property_hooks/bug001.phpt +++ b/Zend/tests/property_hooks/bug001.phpt @@ -27,4 +27,4 @@ try { ?> --EXPECT-- bool(true) -Property C::$x is read-only +Cannot write to get-only virtual property C::$x diff --git a/Zend/tests/property_hooks/bug008.phpt b/Zend/tests/property_hooks/bug008.phpt index 9c321cfe16e14..38fe709a38a3f 100644 --- a/Zend/tests/property_hooks/bug008.phpt +++ b/Zend/tests/property_hooks/bug008.phpt @@ -18,7 +18,7 @@ $foo->bar = 'bar'; ?> --EXPECTF-- -Fatal error: Uncaught Error: Property Foo::$bar is read-only in %s:%d +Fatal error: Uncaught Error: Cannot write to get-only virtual property Foo::$bar in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/property_hooks/get.phpt b/Zend/tests/property_hooks/get.phpt index 0cb0a6b7c76be..6d4b005843eaf 100644 --- a/Zend/tests/property_hooks/get.phpt +++ b/Zend/tests/property_hooks/get.phpt @@ -21,4 +21,4 @@ try { ?> --EXPECT-- int(42) -Property Test::$prop is read-only +Cannot write to get-only virtual property Test::$prop diff --git a/Zend/tests/property_hooks/override_add_get.phpt b/Zend/tests/property_hooks/override_add_get.phpt index 28dbd047c0718..df2739e6086c3 100644 --- a/Zend/tests/property_hooks/override_add_get.phpt +++ b/Zend/tests/property_hooks/override_add_get.phpt @@ -31,7 +31,7 @@ var_dump($b->prop); ?> --EXPECT-- A::A::$prop::set -Property A::$prop is write-only +Cannot read from set-only virtual property A::$prop B::B::$prop::set B::B::$prop::get int(42) diff --git a/Zend/tests/property_hooks/override_add_set.phpt b/Zend/tests/property_hooks/override_add_set.phpt index 6b490d4d87f94..e13de15f0b822 100644 --- a/Zend/tests/property_hooks/override_add_set.phpt +++ b/Zend/tests/property_hooks/override_add_set.phpt @@ -30,7 +30,7 @@ var_dump($b->prop); ?> --EXPECT-- -Property A::$prop is read-only +Cannot write to get-only virtual property A::$prop A::A::$prop::get int(42) B::B::$prop::set diff --git a/Zend/tests/property_hooks/set.phpt b/Zend/tests/property_hooks/set.phpt index 04e36ae85411f..2928aee6cedee 100644 --- a/Zend/tests/property_hooks/set.phpt +++ b/Zend/tests/property_hooks/set.phpt @@ -28,5 +28,5 @@ try { ?> --EXPECT-- int(42) -Property Test::$prop is write-only -Property Test::$prop is write-only +Cannot read from set-only virtual property Test::$prop +Cannot read from set-only virtual property Test::$prop diff --git a/Zend/tests/property_hooks/type_compatibility.phpt b/Zend/tests/property_hooks/type_compatibility.phpt index 8bfb7b0cadd59..def1fc77dc9ce 100644 --- a/Zend/tests/property_hooks/type_compatibility.phpt +++ b/Zend/tests/property_hooks/type_compatibility.phpt @@ -1,5 +1,5 @@ --TEST-- -Relaxed type compatibility for read-only and write-only properties +Relaxed type compatibility for get-only and set-only properties --FILE-- flags & ZEND_ACC_PPP_SET_MASK) && (!prop_info->hooks[ZEND_PROPERTY_HOOK_GET] || !prop_info->hooks[ZEND_PROPERTY_HOOK_SET])) { const char *prefix = !prop_info->hooks[ZEND_PROPERTY_HOOK_GET] - ? "Write-only" : "Read-only"; + ? "set-only" : "get-only"; zend_error_noreturn(E_COMPILE_ERROR, "%s virtual property %s::$%s must not specify asymmetric visibility", prefix, ZSTR_VAL(ce->name), ZSTR_VAL(prop_name)); diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index cca69e5d792c9..22a1d2165774f 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -809,7 +809,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int zend_function *get = prop_info->hooks[ZEND_PROPERTY_HOOK_GET]; if (!get) { if (prop_info->flags & ZEND_ACC_VIRTUAL) { - zend_throw_error(NULL, "Property %s::$%s is write-only", + zend_throw_error(NULL, "Cannot read from set-only virtual property %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); return &EG(uninitialized_zval); } @@ -1150,7 +1150,7 @@ found:; if (!set) { if (prop_info->flags & ZEND_ACC_VIRTUAL) { - zend_throw_error(NULL, "Property %s::$%s is read-only", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); + zend_throw_error(NULL, "Cannot write to get-only virtual property %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); variable_ptr = &EG(error_zval); goto exit; } @@ -2343,7 +2343,7 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has if (!get) { if (prop_info->flags & ZEND_ACC_VIRTUAL) { - zend_throw_error(NULL, "Property %s::$%s is write-only", + zend_throw_error(NULL, "Cannot read from set-only virtual property %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); return 0; } else {