php:“通知”不同机器上的警告
我已经在一台新机器上设置了所有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
新机器中的 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.发出通知的原因是因为您有一个“未定义的常量”。如果您没有在预期的字符串周围加上引号,php 会将其视为常量。如果未定义,php 会将其视为强类型。采取以下示例:
此外,如果您尝试访问数组中未定义的键(例如上面的
$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:
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.
听起来您的错误报告级别因机器而异。比较
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.听起来您有不同的 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.