[resolved] Advice for getting rid of PHP undefined index and undefined variable notices (4 posts)

  1. Joshua
    Posted 2 years ago #


    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: http://kunststube.net/isset/

    Anyway, not sure if you wanted the feedback or not. But either way, thanks again for a great plugin.


  2. Joshua
    Posted 2 years ago #

    Another example fix:

    On line 279 of adrotate.php, change this:

    if ($disabledbanners) {
    to this:
    if (!empty($disabledbanners)) {

    Last example fix:

    change this:

    if($stats_today->impressions == 0) {
    to this:
    if(empty($stats_today->impressions) or $stats_today->impressions == 0) {

    By using !empty, you're checking that the variable is a) instantiated, and b) holding a value that does not evaluate to false. There's more info on it in that article I linked to in my previous post.

  3. Arnan de Gans
    Plugin Author

    Posted 2 years ago #

    This will be dealt with in a future version.

  4. mayuxi
    Posted 2 years ago #

    Joshua, thanks for fixes!

    And Arnan de Gans thanks for the great plugin. I liked it a lot, but I get "Undefined index/variable" in every page, there is just a lot of undefined variable in your plugin :( I believe it's secure...

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • AdRotate
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.