Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

 

I have one simple question. I know it's really basic question but I wanted to clarify what they are...

 

If you see config.inc.php file below:

 

---------------------------------------------------------------------------------------------------------------------

$live = false;

 

 

function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

 

global $live, $contact_email;

 

//build the error message

$message="An error occurred in script '$e_file' on line $e_line:\n$e_message\n";

 

//add the backtrace;

$message.="<pre>".print_r(debug_backtrace(),1)."</pre>\n";

 

if(!$live) { //show the error in the browser

 

echo'<div class="error">'.nl2br($message).'</div>';

 

}else{//development (print the error)

//send the error in an email;

error_log($message,1,$contact_email,'From:admin@example.com');

 

//only print an error message in the browser, if the error isn't a notice.

if($e_number != E_NOTICE) {

echo'<div class="error">A system error occurred. We apologize for the inconvenience.</div>';

}

 

}//end of $live IF-ELSE

 

 

---------------------------------------------------------------------------------------------------------------

 

$live = false; means, as a flag, it's not true. So you can think this is not live.

 

When you look at "if(!$live) {" part, I thought it meant it's live. Because $live = false and !$live is true. However the way this code described was that it meant to be when $live was false..

 

I am confused.. Can you explain it why it is like that?

 

Thank you very much and look forward to hearing from you soon.

Share this post


Link to post
Share on other sites

Prepending an IF statement with ! flips the value of the variable. So if $live is set to FALSE then:

 

if(!$live) { //show the error in the browser

 

Returns TRUE meaning the next code block is executed. So when the $live flag is set to FALSE the following code is executed:

 

echo'<div class="error">'.nl2br($message).'</div>';

 

However when you change the value to TRUE the IF statement evaluates to FALSE meaning the ELSE block gets executed:

 

//send the error in an email;
error_log($message,1,$contact_email,'From:admin@example.com');

//only print an error message in the browser, if the error isn't a notice.
if($e_number != E_NOTICE) {
echo'<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
}

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...