1

I'm getting a series of:

"Undefined variable: loginError in /Library/WebServer/Documents/clients . . ."

entries in my Apache error_log which I would like to prevent. I have a simple login.php page which, if there's an error logging in sets the $loginError variable as such:

$loginError = '<p class="text-error">Login Error: '. $layouts->getMessage(). ' (' . $layouts->code . ')</p>';

If there's no error logging in it does this:

$loginError = '';

I then output any errors as such:

if ($loginError !== '') { //line 112
echo $loginError; /line 113
} 

I'm getting the entries for the line 112 and 113 noted in my comments above. Anyone tell me how I can prevent the entries appearing? I'm using PHP Version 5.3.6.

thanks

2 Answers 2

3

Its saying you should check it is set before using:

One way is with isset()

if (isset($loginError) && $loginError !== '') {
  echo $loginError;
} 

But in your particular case you may as well use !empty()

if (!empty($loginError)) {
  echo $loginError;
} 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks - that's just what I was after.
np, have a look at the empty() man page it is a great little construct.
0

Hard to say without seeing the rest of your code. Trace through your logic to make sure that every possible branch initializes loginError at some point in its execution. Even better, set it to a default value before you go through the logic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.