Ryan R 0 Posted August 23, 2011 Report Share Posted August 23, 2011 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. Quote Link to post Share on other sites
Stuart 68 Posted August 23, 2011 Report Share Posted August 23, 2011 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>'; } Quote Link to post Share on other sites
Ryan R 0 Posted August 23, 2011 Author Report Share Posted August 23, 2011 Thanks Stuart, So, my thought was correct, then. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.