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

From: Date: Mon, 23 Nov 2026 14:50:00 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144056@lists.php.net to get a copy of this message
Author: Ilija Tovilo (iluuu1994) Date: 2026-11-23T15:49:38+01:00 Commit: https://github.com/php/php-src/commit/57db67b967caf5b09352a3b446ad79f2df101031 Raw diff: https://github.com/php/php-src/commit/57db67b967caf5b09352a3b446ad79f2df101031.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix propagation of public(set) of readonly trait property Changed paths: A Zend/tests/asymmetric_visibility/trait_readonly_public_set.phpt M Zend/zend_inheritance.c Diff: 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 335af0c52f40..9e9e247faefd 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 (#144056) next »