Advice for getting rid of PHP undefined index and undefined variable notices
-
Hi,
First and foremost, thanks for a great plugin.
You’re probably aware of all the PHP notices you get about undefined indexes and variables when PHP has error reporting on. Sure, not many people see them. But they still shouldn’t be there, and they’re really simple to fix.
For example – this notice:
Notice: Undefined index: message in /xxx/xxx/www/wp-content/plugins/adrotate/adrotate.php on line 134
All you need to do to fix it is change this line:
$message = $_GET['message'];
to this:
$message = isset($_GET['message']) ? $_GET['message'] : '';
It’s a similar case with almost all other such notices in this plugin. They’re almost all just about using variables which aren’t instantiated. It’d probably only take 15min or so to correct all instances in the plugin.
PHP is relaxed about ininstantiated variables, hence why it gives a notice rather than a full-blown error. But it’s best practice to avoid taking advantage of PHP’s relaxed stance on this. A great article on that topic is here: https://kunststube.net/isset/
Anyway, not sure if you wanted the feedback or not. But either way, thanks again for a great plugin.
- The topic ‘Advice for getting rid of PHP undefined index and undefined variable notices’ is closed to new replies.