php:“通知”不同机器上的警告

发布于 2024-11-05 11:37:11 字数 264 浏览 3 评论 0原文

我已经在一台新机器上设置了所有 php 内容,并且收到了很多通知警告。

我的代码在我的旧机器上运行正常,没有错误。

例如。以下行(应该获取记录集值)将引起通知: $ID = $rs[id];

原因是 id 字段缺少引号,而且对不存在的值调用 $_GET 之类的事情也会引起通知。

有人知道这是什么原因吗? 我很想像在我的旧机器上一样保持“简单”的编码方式,而不必为记录集或大量 isset() 上的引号而烦恼 - 有什么想法吗?

谢谢

i've set up all my php stuff on a new machine and i'm getting really lots of notices warnings.

my code is working properly without errors on my old machine.

eg. the following line (which should get a recordset value) will cause a notice:
$ID = $rs[id];

the reason is the missing quotes for the id fields, but also things like calling $_GET on a non-existing value will cause notices.

anyone knows what's the reason for this?
i'd love keeping the "simple" way of coding like on my old machine without having to hassle with quotes on recordsets or tons of isset() - any ideas?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

镜花水月 2024-11-12 11:37:11

新机器中的 PHP 安装具有更强大的配置,可以显示通知,而不仅仅是错误。那挺好的。我永远不会在我的服务器中编写或接受会引起某些注意的 PHP 脚本。

这种“惰性”编码(请原谅我,我想帮助您!)会带来未来的问题(代码难以阅读和调试),并间接带来安全问题(“惰性”代码通常存在缺陷)。修复所有引发通知的问题。 :)

并且,如果可以的话,学习一些更高级的 PHP:面向对象编程、封装、信息隐藏等……这就是现在的做法,而且比以前工作得更好。围绕通知抑制和 register_globals 构建的旧 PHP 脚本有些转储。

The PHP installation in the new machine has a more robust configuration that shows notices, and not only errors. That's good. I would never write or accept in my server a PHP script that fires some notice.

This kind of "lazy" coding (forgive me, I want to help you!) brings to future issues (code is hard to read and to debug) and, indirectly, security concerns ("lazy" code is often flawed). Fix everything that fires up a notice. :)

And, if you can, learn some more advanced PHP: go for object-oriented programming, encapsulation, information hiding, etc... This is how things are done nowadays and they work better than before. Old PHP scripts, built around notice suppression and register_globals, were somewhat dump.

感性不性感 2024-11-12 11:37:11

发出通知的原因是因为您有一个“未定义的常量”。如果您没有在预期的字符串周围加上引号,php 会将其视为常量。如果未定义,php 会将其视为强类型。采取以下示例:

$array = array(
   'one' => 'right'
   , 'two' => 'wrong'
);
define('one', 'two');

echo $array[one]; //echoes "wrong"

此外,如果您尝试访问数组中未定义的键(例如上面的 $array['two'];),您将收到通知。 PHP 足以为您完成此操作,因为其他语言会出错(或更糟)。

这些通知不仅仅是为了打扰您。它们是为了让您知道您的代码中存在问题,您应该强烈考虑解决该问题。

The reason for the notice is because you have an "undefined constant." If you do not put quotes around an intended string, php will treat it as a constant. If it's not defined, php treats it as a strong. Take the following example:

$array = array(
   'one' => 'right'
   , 'two' => 'wrong'
);
define('one', 'two');

echo $array[one]; //echoes "wrong"

Also, you will get a notice if you try to access a key in an array that is not defined (such as $array['three']; above). PHP is nice enough to do this for you as other languages will error out (or worse).

The notices are not just to bug you. They are to let you know there's a problem in your code that you should strongly consider addressing.

多情出卖 2024-11-12 11:37:11

听起来您的错误报告级别因机器而异。比较 error_reporting 跨机器的 php.ini 中的级别。

Sounds like your error reporting level differs between machines. Compare the error_reporting levels in your php.ini's across machines.

我还不会笑 2024-11-12 11:37:11

听起来您有不同的 error_reporting 值在两台服务器上设置。检查您的 php.ini 并进行相应设置。

It sounds like you have a different error_reporting value set on the two servers. Check your php.ini and set accordingly.

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