5

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

4

4 回答 4

5

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.

于 2011-05-05T19:29:58.723 回答
4

通知的原因是因为您有一个“未定义的常量”。如果您没有在预期的字符串周围加上引号,php 会将其视为常量。如果未定义,php 将其视为强项。举个例子:

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

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

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

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

于 2011-05-05T19:31:50.300 回答
3

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

于 2011-05-05T19:29:15.530 回答
1

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

于 2011-05-05T19:30:11.943 回答