Part 1 · Fundamentals / Readonly bindings
Lesson 3 of 8

Readonly bindings

Add readonly before the type when a variable should keep its initial value. Here, $env stays set to prod:

env.ppphp
readonly string $env = "prod";

Reassignment is a compile error, and the editor tries exactly that. Press Check to see the compiler reject it, then delete the reassignment line:

env.ppphp
$env = "dev";   // delete this line

Check again, then press Run to print prod. Use readonly for a value you want to keep throughout the function, such as a request ID or a retry limit.