Jump to content

PHP notice


Ads

Recommended Posts

Hey I updated my WAMP server the other day and I am getting al of these Errors now.

Notice: Undefined variable: ac in C:\wamp\www\xxxxx\newupdates.php on line 15

 

And there is about 25 of them on one page, and they are all over the place. Undoubtly it is my poor coding, but how come it never showed up before, and the site itself still works.

 

Any help would be great, I basically wont to get rid of these :)

Link to comment
Share on other sites

The best guess would be that the update enabled php warnings which you didn't have on before... You can always turn the warnings off if you find them irritating (not suggested tho on dev machines).

 

Without any proper knowledge about your code my best guess would be to wrap those variables inside if(isset) blocks.

e.g.

if(isset($yourvar)) {
  //dosomething with your var
}

Link to comment
Share on other sites

Different servers are set up to show different levels of errors. PHP Notices are often not shown.

 

That particular notice occurs if you try and use a variable before it has been set.

 

for($i = 0; $i < 5; $i++){
    $var = $var + 1;
}

will cause PHP to issue a notice because the first time around the loop, you're trying to add 1 to $var before $var exists. To avoid this notice, you could do something like;

 

Different servers are set up to show different levels of errors. PHP Notices are often not shown.

 

That particular notice occurs if you try and use a variable before it has been set.

 

$var = 0;
for($i = 0; $i < 5; $i++){
    $var = $var + 1;
}

Or, to use noXstyle's example code;

for($i = 0; $i < 5; $i++){
    if(isset($var)){
        $var = $var + 1;
    }else{
        $var = 1;
    }
}

Link to comment
Share on other sites

It's telling you that your variables are not defined when it first runs.  What you want to do with that is up to you.

 

I just want to get rid of it :P

 

The most easy and painless way possible

Link to comment
Share on other sites

The easiest way is to just disable the display of PHP Notices by changing the error_reporting level. But just hiding the messages doesn't fix your code :P

 

 

You could just initialise the problematic variables at the start of the code segment. Eg;

 

$a = $b = $c = $d = $e = 0;

 

What you initialise them to will depend on your code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.