Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130161 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id E6AE21A00BC for ; Tue, 24 Feb 2026 20:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771964119; bh=ncvQIwvTeTYdyEC2G0BzaQIeMlUsAYrCAnBE1mpHBbs=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=FHOS+AD9Kf82mKQFoGeuwNucEwYGlxe1XOkcuWxN/4VcfqyzWRjw4yjJewscElQco oKGAYOGKnpnB3oFP2ntGbmnXhMerol6uaG44ViXMOspyFk9ZlpSrpj8ZkOzRBis/2b 2CR8WRIQ9UiSB80bOySKyoiTLFiJpzeb2diZvF+oxjwBaAG1thZH3zXokFwc6LGXda iDQWpTrskwRHhtUj4dAJJD/MQEGruvdZ8k/J4fcMG3P53mMwGJwfeRexUZZ+CvSMeK Jfp1VVUPy1EbEXkuMe1Y3MTe1Ml2Nx7jFgQsxtZDxC9Hvhk/VXqf1MYnXAq9ittlqL tiuC+Ctut0wgw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA49F180593 for ; Tue, 24 Feb 2026 20:15:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 24 Feb 2026 20:15:18 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4377174e1ebso4564326f8f.3 for ; Tue, 24 Feb 2026 12:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wcflabs.de; s=google; t=1771964112; x=1772568912; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=p6URkAlNb2symWjzCky6uGODOZy6IeBf+//UdXCNFQQ=; b=e4JgPDSWsAPq+AxCFo3fEiSAgUvlbmbrkpQLKBHdYj9R6oRclB6SOfiQnwUhtph/Gy a/BtY3bIvra191IJ3qZFYwQaA82Lo1e8TyJ1RFK00dIMHtH7+S2Wn/MGikwFIywD38cm dUX7D/kKzcjgNwlklltfXLAS1/Z0jdN1VyHYR/AeTQsum9eYBhk0CFaC5fs1ZIrwfBf2 7XC5sCj5FyD8saQXZWKSaZv4b0z2jAz9yfpYNtQe/ULrIROl/q3afIYqEGkfuFlPWrI4 NCgTvuMgDOihyRIpCWt4U5AOgZ4cck3AZ62tvrLqfROyvpeuyEGwBW7ACU3RqAdT7nC7 V20g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771964112; x=1772568912; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p6URkAlNb2symWjzCky6uGODOZy6IeBf+//UdXCNFQQ=; b=laqP6BoHVUVKJ4cafIBtGPlv1ujSUCeOW8obX5ZXm1Besvb5MzHqEYCAsiDbl2IYa5 WC+TN1LzelmRnhhGsilVQES6PBrLD6M9BhkvhDvjbmm6k5K4QkVtwi0uKRgTc1CGo/vh ZOggXsc1/l55rcTzukNzc5QLJrWSFtdyMQy4LNhQ/PItV7+B+eV6i+ncYmnKYim5piQT P6butg31/ErlRKYZVCR5WyPOZcebrGSUWAMKeAhTLmECcdDQW+E5evU+6VHGAvzDQyhb xOxIQjZznI3Sigdf9a+4KiYgl8NiR4Z49ENAIf8DYJRxq9ndU2iFkD8fR+VJdHXVk69x kZ2w== X-Gm-Message-State: AOJu0YwjaGG3Apkky20gA267NYkJiT2mj31EWr2I4w8DTTUd7arDj9vk oYcLh4aisBRJPakI0XLhzOsfg+3BczgMyCstCwhqGDi4C9VvVDXiFpOnMpzbhA/oFxcOJInLVTw STujG X-Gm-Gg: ATEYQzzLaqjNUClB5oWLFndOjw8V+fIiMLiOM85R/7eqpnVlMjhyEn+4HkmhXJeluwf QBmQ4Q755NVZWXbxRvwbgWlwR6oQ6JeZSEFu4X/FIxgCbY9QmA5lq9vGYVLIwQrHcIODE7mEza3 wkKg9PSLb11CLIPH9/Cz/8m4Qa/C8LL2UQ3wmJsqnUTWicPp57+gsm4VKeZXXdta+ZCfy5EUUBv a7KQz+sCxB0K3LL2MvUrYgDgPFJ5/ljoazgpSxtz8hM6rJaF5CXFAUYETHsCrA8MMY26gS+X8JW 2ccl/el3S/MuLkj2e20zaCRO3O9L51RF36sm9/ILEKjhfCwke9g5ErOWd/8Wyakw7Ag2YXbxMP+ bZgBWYliKXQ0LXryi3McjxzPD8KwJqgb8MiElbsQJQeleZu7F/6nQNC5+aB2gIl8IYh9fdK8gq8 b8G2Pakw7SEluP+/olXyKHjOz4IGpBsj5amR7DvmqrQBZuansJuuzvV+WOYrhcBclGB9U0V3Gml 4AI5ZAtZohv3c4OvgmpXoYsVHxOA71D23orfEY= X-Received: by 2002:a5d:5f48:0:b0:430:fdc8:8be3 with SMTP id ffacd0b85a97d-4396f18308dmr23963363f8f.29.1771964112455; Tue, 24 Feb 2026 12:15:12 -0800 (PST) Received: from smtpclient.apple (p200300e91f342b589d745db7d00ff1de.dip0.t-ipconnect.de. [2003:e9:1f34:2b58:9d74:5db7:d00f:f1de]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d54754sm29409519f8f.36.2026.02.24.12.15.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2026 12:15:12 -0800 (PST) Content-Type: text/plain; charset=utf-8 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: Re: [PHP-DEV] [RFC] Readonly Variables In-Reply-To: <20260224004547.C3CD51A00BD@lists.php.net> Date: Tue, 24 Feb 2026 21:15:01 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <20260224004547.C3CD51A00BD@lists.php.net> To: Ben Ramsey X-Mailer: Apple Mail (2.3864.300.41.1.7) From: josh@wcflabs.de (=?utf-8?Q?Joshua_R=C3=BCsweg?=) Hi Ben,=20 > On 24. Feb 2026, at 01:45, Ben Ramsey wrote: >=20 > According to this RFC, both of these would be forbidden: >=20 > readonly $a =3D new Foo(); > $b =3D $a; As Tim already clarified, there is a common misconception about how PHP = handles objects internally. In PHP, objects are not passed by reference = in the sense of the `&` operator, but via an object identifier. This = means that `$b =3D $a` simply copies the object identifier, not a = reference to the variable itself, and is therefore perfectly valid: ``` and: >=20 > function modify(Foo $value): void {} > readonly $a =3D new Foo(); > modify($a); >=20 > I said "according to this RFC," but the RFC doesn't mention object = behavior with readonly at all, which I think might be an oversight. The = only place it hints at allowing objects is in the examples with `new = PDO()`. >=20 > Is the idea to allow objects (and arrays) similar to how JavaScript = handles these with `const`? That is, the objects and arrays themselves = are mutable, but the variable name cannot be reassigned to a new object = or array? Regarding your question about object and array behavior: you are correct = that the RFC did not explicitly document this, which was indeed an = oversight on my part. As already mentioned above, the variable binding is immutable, meaning = `$a` cannot be reassigned to a different object, but the internal state = of the object can still be modified. This is also consistent with how = the readonly attribute behaves for class properties: ``` value =3D "foo"; // Valid: modifying the object's internal state is = allowed $a =3D new Foo(); // Error: Cannot re-assign readonly variable ``` For arrays, however, the behavior differs from JavaScript. In PHP, = arrays are value types with copy-on-write semantics, not reference = types. This means that a readonly array is fully immutable, as neither = the array itself nor its elements can be modified after the initial = assignment: ```