PHP中有没有类似于VB中的Option Explicit的东西
可能的重复:
PHP 中的严格模式?
我正在用 PHP 做一个大项目。在 PHP 中,您不需要声明变量。这给我带来了很多问题。
在 Visual Basic 6 中,Option Explicit 语句强制声明变量。 PHP 中有类似的东西吗?
Possible Duplicate:
Strict mode in PHP?
I am doing a big project in PHP. In PHP you do not need to declare variables. This is causing a lot of problems for me.
In Visual Basic 6, the Option Explicit statement makes it mandatory to declare variables. Is something similar available in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您打开 E_NOTICE 错误消息,PHP 将告诉您有关未初始化变量的信息:
未初始化与未声明有点不同,但它应该给您带来类似的效果。
If you turn on E_NOTICE error messages, PHP will tell you about uninitialized variables:
Uninitialized is a little bit different than undeclared, but it should give you a similar effect.
当您尝试使用未定义的变量时抛出一条通知
更一般的提示:使用函数而不是全局代码,并使它们变小(最多 20 行)。由于变量是函数的局部变量,因此忘记或拼错变量名称的可能性较小。
throws a notice when you attempt to use an undefined variable
a more general tip: use functions instead of global code, and make them small (max. 20 lines). Since variables are local to functions, there's less chance to forget or misspell a variable name.
增加 错误报告级别 仅在未定义的变量/元素用作右值时影响 php 的行为,例如 <代码>echo $doesnotexist;。
但是
选项显式
< /a> 还禁止使用未声明的变量作为左值php 中没有类似的选项或配置参数。
Increasing the error reporting level only affects php's behaviour when an undefined variable/element is used as rvalue, like
echo $doesnotexist;
.But
option explicit on
also prohibits the use of undeclared variables as lvalueThere's no similar option or config parameter in php.