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

Fix asymmetric visibility with set hook

Fixes GH-15644
Closes GH-15645
This commit is contained in:
Ilija Tovilo
2024-08-30 00:05:47 +02:00
parent e8fe7e4f52
commit e12188fe89
3 changed files with 41 additions and 0 deletions

1
NEWS
View File

@@ -4,6 +4,7 @@ PHP NEWS
- Core:
. Fixed bug GH-15330 (Do not scan generator frames more than once). (Arnaud)
. Fixed bug GH-15644 (Asymmetric visibility doesn't work with hooks). (ilutov)
- DOM:
. Fixed bug GH-13988 (Storing DOMElement consume 4 times more memory in

View File

@@ -0,0 +1,32 @@
--TEST--
GH-15644: Asymmetric visibility doesn't work for set hook
--FILE--
<?php
class C {
public private(set) string $prop1 {
set => $value;
}
public private(set) string $prop2 {
get => $this->prop2;
}
}
$c = new C();
try {
$c->prop1 = 'hello world';
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
$c->prop2 = 'hello world';
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot modify private(set) property C::$prop1 from global scope
Cannot modify private(set) property C::$prop2 from global scope

View File

@@ -1057,6 +1057,14 @@ found:;
}
goto try_again;
}
if (UNEXPECTED(prop_info->flags & ZEND_ACC_PPP_SET_MASK
&& !zend_asymmetric_property_has_set_access(prop_info))) {
zend_asymmetric_visibility_property_modification_error(prop_info, "modify");
variable_ptr = &EG(error_zval);
goto exit;
}
GC_ADDREF(zobj);
zend_call_known_instance_method_with_1_params(set, zobj, NULL, value);
OBJ_RELEASE(zobj);