I read the Zephir's documentation (https://docs.zephir-lang.com/0.12/en/types) and I'm not sure I understand the difference between var
and let
in Zephir. My first thought was that maybe var
only declares a variable and if you want to assign it to something, you have to use let
. But then I saw the following lines in the documentation:
var a = false, b = true;
var number = 5.0, b = 0.014;
and I'm quite confused now.
Per the docs:
Variables are, by default, immutable. This means that Zephir expects that most variables will stay unchanged. Variables that maintain their initial value can be optimized down by the compiler to static constants. When the variable value needs to be changed, the keyword let must be used.
In other words, your assumption seems right. The reason the sample you posted uses var
is because those are initial assignments as opposed to reassignments. Immutable, in that context, means that Zephir expects variables to maintain their original values.