Undefined indicies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Slightly off topic, I apologise.

Total newbie.  In many php DB tutorials I've seen, it's recommended to set
register_globals off, and error reporting to E_ALL.

When I looked at my system, register_globals was enabled and error reporting
was set to E_FATAL.  I changed them to the suggested values (off and E_ALL),
and all hell broke loose.  Clearly, I must not be very good at PHP yet.  ;)

First question:

register_globals is a matter of security, so that's definitely valuable to
turn off.  Is setting error reporting really useful if my aim is to become a
better PHP programmer?

I'm thinking along the lines of lint/splint, where this line of code in C:

   printf("hello world\n");

generates a useless warning because I'm not using printf()'s return value.
I'm wondering whether it's useful for a scripting language, like PHP, to
warn me when I use code like:


   if ( $_REQUEST['action'] == 'foo' )
      do_something;


when I don't access the URL with a "?action=foobar" type request.

Should I change error reporting back to "E_FATAL" or is being this
compulsive about warnings good for me (and my security)?



Second question:

If being compulsive is good for me, what's the best way of handling
something like above?   From browsing php.net, I've thought of a few ways,
like a "controlled" suspension of compulsion:


   if ( @ $_REQUEST['action'] == 'foo' )
      do_something;

or, lord forbid:

   if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'foo' )
      do_something;

and also variations on a theme:

   if ( array_key_exists('action', $_REQUEST )
      $action = $_REQUEST['action'];

   if ( isset($action) )
      do_something;


Personal preference must play into this, but I'm wondering what more
experienced PHP programmers do.  My code is riddled with this kind of thing.

Thanks (and sorry for the long winded / slightly off-topic post!)

Pete

-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux