On Tue, 24 Feb 2026, 00:00 Kamil Tekiela, <tekiela246@gmail.com> wrote:
On Mon, 23 Feb 2026 at 21:29, Joshua Rüsweg <josh@wcflabs.de> 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 local or functional scope. This RFC proposes the readonly modifier for variables, which prevents reassignment after the initial declaration and results in an error on any attempt to do so.
The RFC is available at:
https://wiki.php.net/rfc/readonly-variablesI’m looking forward to your feedback and discussion.
Cheers,
Joshua RüswegHi Joshua,
This is a very interesting proposal, but I feel like you haven’t
explained all your choices. I have some questions:
- Why the use of readonly keyword? Why not const or some new keyword,
e.g. locked.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().
Hi Kamil, Joshua,
I wrote on this topic in the past: https://news-web.php.net/php.internals/126909
and I think we already cannot use readonly and final for parameter, as that conflicts with constructor parameter promotion:
if we ever decide to use the final modifier for a
parameter, it would not be possible.
it is already not possible to use the readonly modifier for a parameter
because of this
I think that using const keyword might be one of the best options.
–
Alex