1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Tweak get/set-only hook error messages

Fixes GH-19845
Closes GH-19916
This commit is contained in:
Ilija Tovilo
2025-09-22 12:42:56 +02:00
parent 595eb04687
commit 5b8a5320df
12 changed files with 15 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -27,4 +27,4 @@ try {
?>
--EXPECT--
bool(true)
Property C::$x is read-only
Cannot write to get-only virtual property C::$x

View File

@@ -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

View File

@@ -21,4 +21,4 @@ try {
?>
--EXPECT--
int(42)
Property Test::$prop is read-only
Cannot write to get-only virtual property Test::$prop

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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--
<?php

View File

@@ -1,5 +1,5 @@
--TEST--
Invalid type compatibility for read-only property
Invalid type compatibility for get-only property
--FILE--
<?php

View File

@@ -1784,7 +1784,7 @@ ZEND_API void zend_verify_hooked_property(const zend_class_entry *ce, zend_prope
&& (prop_info->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));

View File

@@ -809,7 +809,7 @@ try_again:
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 @@ found:
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 {