I just setup a new server running php5, an upgrade from the last server running php4 and I'm migrated all my websites to the new server with php5. I keep getting these "Undefined variable" errors for variable that haven't been set. I know I can could code in an isset() for every variable in an if statement to work around this but is there any other way that isn't so tedious. Maybe a setting in php.ini to ignore it? Thanks for any help.
This is bad. All this is bad. It seems like your PHP4 code was a little bit not correct, and was ignoring variable setting (99% php developers do so). You can use @, error_reporting, ini_set, htaccess, php.ini to turn off reporting for notices, but remember - small notice leads to huge errors in the end
Thanks guys, all very helpful. It's been a while since i setup php on a server. I know not setting and checking varibles is BAD but that is why I like it, haha - I'm such a php loser.
Yeah. Always make sure a variable exists before using them!! use something like this: $var = $var ? $var : ""; PHP: This above will set the variable if it is not set.
no need to do this. all you need to do is to go to php.ini and set: error_reporting = E_ALL & ~E_NOTICE Code (markup):
Or use ini_set... or, god forbid, code it right? Just because you can do something, doesn't mean you should!
I have different settings for different scripts. For instance if its juts some raggy application for personal use (like maybe a cron update) I will go without any error reporting at all. Any site that goes live though will get the ol E_ERROR ^ E_WARNING
Code it right But that means you need to create more blank spaces between the lines... and more words... it's a whole nother 15 BYTES!.. lolol