Skip to content

Commit a699796

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: Fix propagation of public(set) of readonly trait property
2 parents 1be37f6 + 9b320b9 commit a699796

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ PHP NEWS
4141
(Nicolas Grekas)
4242
. Fixed bug GH-25571 (Incorrect null handlers when generating unspecialized
4343
Zend VMs). (Weilin Du)
44+
. Fixed propagation of public(set) of readonly trait property. (ilutov)
4445

4546
- Curl:
4647
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
public(set) of trait property is properly propagated
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
public public(set) readonly int $pub;
8+
protected readonly int $prot;
9+
private readonly int $priv;
10+
11+
public function modify($prop) {
12+
$this->{$prop} = 42;
13+
try {
14+
$this->{$prop} = 43;
15+
} catch (\Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), "\n";
17+
}
18+
var_dump($this->{$prop});
19+
}
20+
}
21+
22+
class C {
23+
use T;
24+
}
25+
26+
$c = new C;
27+
28+
$c->pub = 42;
29+
try {
30+
$c->pub = 43;
31+
} catch (\Throwable $e) {
32+
echo $e::class, ': ', $e->getMessage(), "\n";
33+
}
34+
var_dump($c->pub);
35+
36+
$c->modify('prot');
37+
$c->modify('priv');
38+
39+
?>
40+
--EXPECT--
41+
Error: Cannot modify readonly property C::$pub
42+
int(42)
43+
Error: Cannot modify readonly property C::$prot
44+
int(42)
45+
Error: Cannot modify readonly property C::$priv
46+
int(42)

‎Zend/zend_inheritance.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,11 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
29032903
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&traits[i]->properties_info, prop_name, property_info) {
29042904
uint32_t flags = property_info->flags;
29052905

2906+
/* ZEND_ACC_PUBLIC_SET is removed at compile-time. */
2907+
if ((flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_MASK|ZEND_ACC_PPP_SET_MASK)) == (ZEND_ACC_READONLY|ZEND_ACC_PUBLIC)) {
2908+
flags |= ZEND_ACC_PUBLIC_SET;
2909+
}
2910+
29062911
/* next: check for conflicts with current class */
29072912
if ((colliding_prop = zend_hash_find_ptr(&ce->properties_info, prop_name)) != NULL) {
29082913
if ((colliding_prop->flags & ZEND_ACC_PRIVATE) && colliding_prop->ce != ce) {

0 commit comments

Comments
 (0)