Re: [php-src] PR #20903: GH-10497 (const obj->prop write) - language change notes

From: Date: Wed, 21 Jan 2026 23:33:06 +0000
Subject: Re: [php-src] PR #20903: GH-10497 (const obj->prop write) - language change notes
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-129835@lists.php.net to get a copy of this message
Hi Tim On Sun, Jan 18, 2026 at 1:28 PM Tim Düsterhus <tim@bastelstu.be> wrote: > > On 1/15/26 07:36, Khaled Alam wrote: > > A potentially surprising case: some newly-valid writes can be a no-op > > when they target a temporary const value, e.g. > > - const X = [1,2,3]; X[] = 4; > > - const Y = ['a' => 1]; Y['b'] = 2; > > > > These become valid syntax but have no effect because the write happens on a > > temporary basis. > > > > Feedback on semantics + expected behavior for the temporary-write case is > > appreciated. > > This is too unexpected / error-prone for me. Trying to write into arrays > should remain disallowed / an Error, since this is never (?) useful. No strong opinions on my part, but I'd like to point out that similar situations already exist. https://3v4l.org/ARMMS#v8.4.14 const C = [1, 2, 3]; function foo(): array { return C; } foo()[] = 4; var_dump(C); PHP will happily duplicate the array returned from foo() to append 4, without warning. The original array in C remains unmodified. It might make sense for ASSIGN_DIM to warn/throw if OP1 is not a "pointer" (indirect, reference or object), as then the operation will never have an effect. But it seems to me this is a distinct issue. Ilija

« previous php.internals (#129835) next »