Skip to content

Commit e12188f

Browse files
committed
Fix asymmetric visibility with set hook
Fixes GH-15644 Closes GH-15645
1 parent e8fe7e4 commit e12188f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug GH-15330 (Do not scan generator frames more than once). (Arnaud)
7+
. Fixed bug GH-15644 (Asymmetric visibility doesn't work with hooks). (ilutov)
78

89
- DOM:
910
. Fixed bug GH-13988 (Storing DOMElement consume 4 times more memory in
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-15644: Asymmetric visibility doesn't work for set hook
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public private(set) string $prop1 {
8+
set => $value;
9+
}
10+
public private(set) string $prop2 {
11+
get => $this->prop2;
12+
}
13+
}
14+
15+
$c = new C();
16+
17+
try {
18+
$c->prop1 = 'hello world';
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
try {
24+
$c->prop2 = 'hello world';
25+
} catch (Error $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
29+
?>
30+
--EXPECT--
31+
Cannot modify private(set) property C::$prop1 from global scope
32+
Cannot modify private(set) property C::$prop2 from global scope

Zend/zend_object_handlers.c

+8
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,14 @@ found:;
10571057
}
10581058
goto try_again;
10591059
}
1060+
1061+
if (UNEXPECTED(prop_info->flags & ZEND_ACC_PPP_SET_MASK
1062+
&& !zend_asymmetric_property_has_set_access(prop_info))) {
1063+
zend_asymmetric_visibility_property_modification_error(prop_info, "modify");
1064+
variable_ptr = &EG(error_zval);
1065+
goto exit;
1066+
}
1067+
10601068
GC_ADDREF(zobj);
10611069
zend_call_known_instance_method_with_1_params(set, zobj, NULL, value);
10621070
OBJ_RELEASE(zobj);

0 commit comments

Comments
 (0)