Zephir中var和let有什么区别

What's the difference between var and let in Zephir

我阅读了 Zephir 的文档 (https://docs.zephir-lang.com/0.12/en/types),但不确定我是否理解 Zephir 中 varlet 之间的区别。我的第一个想法是,也许 var 只声明了一个变量,如果你想将它赋值给某个东西,你必须使用 let。但后来我在文档中看到了以下几行:

var a = false, b = true;
var number = 5.0, b = 0.014;

我现在很困惑。

根据 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.

也就是说,你的假设似乎是正确的。您发布的示例使用 var 的原因是因为这些是 初始分配 而不是 重新分配 。在这种情况下,不可变意味着 Zephir 期望变量保持其原始值。