Support » Plugin: AdRotate Banner Manager » Advice for getting rid of PHP undefined index and undefined variable notices

  • Resolved Joshua



    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:

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joshua


    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.

    Plugin Author Arnan de Gans


    This will be dealt with in a future version.

    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…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Advice for getting rid of PHP undefined index and undefined variable notices’ is closed to new replies.