[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Mon, 23 Nov 2026 14:49:57 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144055@lists.php.net to get a copy of this message
Author: Ilija Tovilo (iluuu1994) Date: 2026-11-23T15:49:12+01:00 Commit: https://github.com/php/php-src/commit/a699796d09c4e33bc3ba6bd23e27bcc5aabb8313 Raw diff: https://github.com/php/php-src/commit/a699796d09c4e33bc3ba6bd23e27bcc5aabb8313.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: 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 e45546348807..f2dc4c3302b9 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,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 dd4fbb8e5868..b1e6947b61bb 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -2903,6 +2903,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) {

« previous php.cvs (#144055) next »