[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Ilija Tovilo | Date: | Mon, 23 Nov 2026 14:49:57 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144054@lists.php.net to get a copy of this message | ||
Author: Ilija Tovilo (iluuu1994)
Date: 2026-11-23T15:48:53+01:00
Commit: https://github.com/php/php-src/commit/9b320b9e8f1c9b26a7c1cdb368c2f3ac4b5cb526
Raw diff: https://github.com/php/php-src/commit/9b320b9e8f1c9b26a7c1cdb368c2f3ac4b5cb526.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Fix propagation of public(set) of readonly trait property
Changed paths:
A Zend/tests/asymmetric_visibility/trait_readonly_public_set.phpt
M NEWS
M Zend/zend_inheritance.c
Diff:
diff --git a/NEWS b/NEWS
index c02edbf7d6c7..5bddd9a26994 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ PHP NEWS
(Nicolas Grekas)
. Fixed bug GH-25571 (Incorrect null handlers when generating unspecialized
Zend VMs). (Weilin Du)
+ . Fixed propagation of public(set) of readonly trait property. (ilutov)
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/tests/asymmetric_visibility/trait_readonly_public_set.phpt
b/Zend/tests/asymmetric_visibility/trait_readonly_public_set.phpt
new file mode 100644
index 000000000000..570524abfa1a
--- /dev/null
+++ b/Zend/tests/asymmetric_visibility/trait_readonly_public_set.phpt
@@ -0,0 +1,46 @@
+--TEST--
+public(set) of trait property is properly propagated
+--FILE--
+<?php
+
+trait T {
+ public public(set) readonly int $pub;
+ protected readonly int $prot;
+ private readonly int $priv;
+
+ public function modify($prop) {
+ $this->{$prop} = 42;
+ try {
+ $this->{$prop} = 43;
+ } catch (\Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+ }
+ var_dump($this->{$prop});
+ }
+}
+
+class C {
+ use T;
+}
+
+$c = new C;
+
+$c->pub = 42;
+try {
+ $c->pub = 43;
+} catch (\Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+var_dump($c->pub);
+
+$c->modify('prot');
+$c->modify('priv');
+
+?>
+--EXPECT--
+Error: Cannot modify readonly property C::$pub
+int(42)
+Error: Cannot modify readonly property C::$prot
+int(42)
+Error: Cannot modify readonly property C::$priv
+int(42)
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index cdc62d1665a9..55caf08548d5 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -2907,6 +2907,11 @@ static void zend_do_traits_property_binding(zend_class_entry *ce,
zend_class_ent
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&traits[i]->properties_info, prop_name, property_info) {
uint32_t flags = property_info->flags;
+ /* ZEND_ACC_PUBLIC_SET is removed at compile-time. */
+ if ((flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_MASK|ZEND_ACC_PPP_SET_MASK)) ==
(ZEND_ACC_READONLY|ZEND_ACC_PUBLIC)) {
+ flags |= ZEND_ACC_PUBLIC_SET;
+ }
+
/* next: check for conflicts with current class */
if ((colliding_prop = zend_hash_find_ptr(&ce->properties_info, prop_name)) != NULL) {
if ((colliding_prop->flags & ZEND_ACC_PRIVATE) && colliding_prop->ce != ce) {