PHP中有没有类似于VB中的Option Explicit的东西

发布于 2024-08-21 22:33:22 字数 277 浏览 7 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫卆 2024-08-28 22:33:22

如果您打开 E_NOTICE 错误消息,PHP 将告诉您有关未初始化变量的信息:

ini_set("error_reporting", E_ALL);

未初始化与未声明有点不同,但它应该给您带来类似的效果。

If you turn on E_NOTICE error messages, PHP will tell you about uninitialized variables:

ini_set("error_reporting", E_ALL);

Uninitialized is a little bit different than undeclared, but it should give you a similar effect.

梦在深巷 2024-08-28 22:33:22
error_reporting(E_ALL);

当您尝试使用未定义的变量时抛出一条通知

更一般的提示:使用函数而不是全局代码,并使它们变小(最多 20 行)。由于变量是函数的局部变量,因此忘记或拼错变量名称的可能性较小。

error_reporting(E_ALL);

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.

忆依然 2024-08-28 22:33:22

增加 错误报告级别 仅在未定义的变量/元素用作右值时影响 php 的行为,例如 <代码>echo $doesnotexist;。
但是选项显式< /a> 还禁止使用未声明的变量作为左值

Option Explicit On
Dim x As Integer
x = 10
y = 11 ' error, variable is not declared

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 lvalue

Option Explicit On
Dim x As Integer
x = 10
y = 11 ' error, variable is not declared

There's no similar option or config parameter in php.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文