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

Fuxi
  • 7,611
  • 25
  • 93
  • 139
  • 1
    `any ideas?` - try to write beautiful code. Or normal. Or not smelling, at least. http://pear.php.net/manual/en/coding-standards.php http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1 – OZ_ May 05 '11 at 19:30

4 Answers4

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.

gd1
  • 11,300
  • 7
  • 49
  • 88
  • which kind of security concerns do u mean? is it really that important? thx – Fuxi May 05 '11 at 19:30
  • Well, it does not *directly* bring security issues, but indirectly. I've seen by experience that 'lazy' code is often insecure too, and it's always hard to debug and maintain. – gd1 May 05 '11 at 19:33
4

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.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
3

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

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
1

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

AJ.
  • 27,586
  • 18
  • 84
  • 94
  • You mean set accordingly so that it always prints any kind of notice. Don't you?? – gd1 May 05 '11 at 19:35
  • Hrrm, not necessarily. Verbosity shouldn't always be perceived as a plus. – AJ. May 05 '11 at 19:36
  • 1
    It's not verbosity. You shouldn't be satisfied with a PHP script that fires notices, you should suppress verbosity by removing the cause of the notice. This laziness is a pre-PHP5 legacy that should be extirpated :) – gd1 May 05 '11 at 19:37