Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top