Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130144 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 EC66B1A00BC for ; Mon, 23 Feb 2026 21:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771883912; bh=EY8hNHGavKDRyuAW8sB/vHwuOKVtFf+IE+h2TC7xcRQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GzkVGOBOCoWhgh12x2py+XcvbpAJwQffCi+U5aO7gElHj9di48mv6cfdiDVC+ii5x UPW5J+WhIhzm4Y1Kv1ENBCSJTD6Koof9b551J/obOKCOf/E3saUrASQN+KKcyOqWRG jb9m3rOqq13wXLdhg8VovQachWoixGNKDMqNeE9rTCPCBdf4Dh8B0MGpsrorDenDk0 5VXCVzxwo5/M7nnCKKD1oozkYXcbj9/m/mCpPnioJJXQD84FvGNdrpTOJ9C6q8LQyb RIIJFA4css1AwGOAYugIQKkEyckj9VAJUB0G8mqUbJCBzh5gshlaZQaBvotuVtJ/Oa +x2CRaF22D7gA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EA1D21804D3 for ; Mon, 23 Feb 2026 21:58:31 +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.9 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,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-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Mon, 23 Feb 2026 21:58:31 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3870c7479c0so44880731fa.3 for ; Mon, 23 Feb 2026 13:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771883905; cv=none; d=google.com; s=arc-20240605; b=SHIE7RM7n30VkoJOkhU+wPleqEZpwEvazEIRnbVpJJ+1hEKqluvT9tFFwQx/TCiaQ+ TB+zQsAhIHHbhlX0LOTP3vIFGZ7GyI+avFRl0+6djJwk0tOIR44kMWNiEk8iialwrPaM gR6Pq/6wVhX/0bNAdgZW3L2uSvMdRiWkcVdwfo03igs6fUkGDRZgmjgquNAgOcvQQ920 MhsIhy+FXdsAYdemkXOx8CObRvqaWV7vCGe+4x7x5Gms4nIKrADHV7H6gebTKsE8Fbnv kNw5HkZvmKJoXZb9fagRZ+gmL2RxeDfZvJUgBMha3DxvHT4tQ/Yh3gjrj+/PXZvEeHGm v2zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EY8hNHGavKDRyuAW8sB/vHwuOKVtFf+IE+h2TC7xcRQ=; fh=PrQHppe/P+V/r9Ep2FUqtk4DMOb3OgTy7AMUjByVH64=; b=fpLlAjfYMPM61pIB31MF0sJsuedjEPu/jM2NZsBpCumn7A9Sjzj0OJXxKhYe+D5Ido MlvTSzFnGA3f2rAqOAUc6V5WSmxHYAN7sBKziLLDV5FnE0vvLx34JDjE64C3kfWao3w4 iMJmTtGM4KnyI9rPgcvazebz4uMmMn+X8lqpEgRebnIOcIzW7755NikmF+8CCz5ei7Ua atesBO7wItX61t1HpUmqH0gwwUpgU9XmdtfY3VBpgRbXuHeY8sdqHCdEyA/Q3koAxL1x OqNg+fkR1ESyOxELPsPBmgG49wBbSvHB25jdHhVdawDr38YpVIdZrIyv+CW6pv0tXnet 0XDQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771883905; x=1772488705; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EY8hNHGavKDRyuAW8sB/vHwuOKVtFf+IE+h2TC7xcRQ=; b=aAR2tc5eJiqhozIrFG+fStfZTxxJHEGkkpsDu2neYTtzSk1r3Ne6q6jwsOWZP05qOz 6qO8LxtfqqpuN6ZCPczSZmAyZfgxmPR9W3ehGqK2dmasJEHBanKEPavs9jJxgCICKnY3 bdmv5mlMLn4MPRJx3WJtbkqCMbPHCw1ymN/OPWfd3gIfz1SMuNAp2Rstum0+TKwkGJ18 8cGYBLGEdyI9dFXstyIKGm6p20qZXWlfYVG8Y5GEkcqTGZSzPRjo13JwEstqs4mS22Tt UF3EkLXutcoq72XD/TY0Byf5wTZ9P2zCIVLSThgLTmLuz8MnIswa7bp+iOXcnlIs+gUd 9i3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771883905; x=1772488705; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EY8hNHGavKDRyuAW8sB/vHwuOKVtFf+IE+h2TC7xcRQ=; b=jUZN01ihwwds5Nb7nO/v9Jc996Sh94UjeLim8IF4xX2Eg/hwwzxVBfz5lCZzM9v6ER ncgmScvZdtqeE1W4O0vL3FEwGPw3J9yohR6NBRH/ZtUJr+O26hcrfbIpVteKevsj7otl L8/9KpXJXL2DRYvnQR2456ROKd/uBwRte+93ymv5l/GJvyqeEkzKMHSPYsaNiaqe9dF0 Q2so7GmYwa7szy3KIV9aOOWtEeY+9hgChs6fEUEYrwbl4viC6KR3W8OOVeZmbEURvpC4 Mi7uTLmkpM9aNUripmlLoi+B6x2qU9UxiTF7r8/97vLIo0Byul20zrKYKhDNr+aAvBBw X6xw== X-Gm-Message-State: AOJu0Yw8k5bQsg6s8sGltbZfGtFrcDtUepgsHpUNMjCO3i3qZYXihvYB GE4/PORIfIyzJX/DexDlZqmJ4Ouzv840+6BNvv2s6j2Hdn1XLA3bAnVKwtDF7hP4Mm2qqKBRxQd 38lQLPmFE31je8r4y+Fw3H4dC/vj8cm/LMT/X X-Gm-Gg: ATEYQzx2rxsILIlmxYH+TiBbTBHIYGTA3aG7t8qlox1b3SNvvan8EHtqQvmtcDgKAqp bXhQc2Se/JYiQdB98n2W8F8BTaBAqEKtoKlkh6hLNbSpVud5iYhRlh6R5n45m3sFrodksJA3z3z iMBzwMf11pyaib7VTRsMglUjhSKWJVwDcEVJPu+wNPTKqbfWom2cFotG0vV/EDoyQIeWR4aBb+c ebwlyIG6IDI6IfCNk1ytnB3+RJQqFYXxpMhSts/oSWoS0yhbo3BPTVWiSLupo+0uJSrdTl/6QtZ bU3jv34= X-Received: by 2002:a05:651c:211b:b0:37f:c5ca:a10b with SMTP id 38308e7fff4ca-389a5cded40mr26011241fa.4.1771883905005; Mon, 23 Feb 2026 13:58:25 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 23 Feb 2026 21:58:15 +0000 X-Gm-Features: AaiRm52IoYdVw_DpKVIXj2-oqVcRmXo4Eqn3dxSQzx4uaOn0hthpXufmZ0PVoI8 Message-ID: Subject: Re: [PHP-DEV] [RFC] Readonly Variables To: =?UTF-8?Q?Joshua_R=C3=BCsweg?= Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tekiela246@gmail.com (Kamil Tekiela) On Mon, 23 Feb 2026 at 21:29, Joshua R=C3=BCsweg wrote: > > Hi internals, > > I'd like to propose a new language feature for PHP: Readonly Variables. > > PHP currently has no way to declare a variable as immutable within a loca= l or functional scope. This RFC proposes the readonly modifier for variable= s, which prevents reassignment after the initial declaration and results in= an error on any attempt to do so. > > Key behaviors: > - Reassignment and compound assignment operators are forbidden > - Pass-by-reference is forbidden > - unset() removes the readonly flag, allowing re-declaration > - Readonly variables inside loops are permitted but limited to a single d= eclaration > - Scoping follows regular variable rules (function, method, closure bound= aries) > > The RFC is available at: > https://wiki.php.net/rfc/readonly-variables > > I'm looking forward to your feedback and discussion. > > Cheers, > Joshua R=C3=BCsweg Hi Joshua, This is a very interesting proposal, but I feel like you haven't explained all your choices. I have some questions: 1. Why the use of readonly keyword? Why not const or some new keyword, e.g. locked. 2. Why does unset not remove the variable completely? If you want a feature to only unlock the variable then it probably needs a new keyword, e.g. unlock 3. What exactly does this mean: "Readonly variables inside loops are permitted but limited to a single declaration"? What does a single declaration look like? 4. How will this impact optimizer and JIT? 5. You said that readonly variables cannot be used with the global keyword. But what about readonly variables in global scope? Will they still behave like a typical global variable? 6. What exactly counts as a variable declaration? When is it a valid syntax to use this keyword? I don't think PHP had the concept of variable declaration until now. 7. What about compound variables such as arrays and objects? I would prefer starting with readonly parameters as I feel that would bring the most value. I think it would also be worthwhile to investigate a simpler syntax for define(). Regards, Kamil