error-reporting

How to find a reason when mkdir fails from PHP?

馋奶兔 提交于 2019-11-26 21:10:49
问题 PHP's mkdir function only returns true and false. Problem is when it returns false. If I'm running with error reporting enabled, I see the error message on the screen. I can also see the error message in the Apache log. But I'd like to grab the text of the message and do something else with it (ex. send to myself via IM). How do I get the error text? Update: Following Ayman's idea, I came to this: function error_handler($errno, $errstr) { global $last_error; $last_error = $errstr; } set_error

Where do you like to catch exceptions and why?

拈花ヽ惹草 提交于 2019-11-26 16:38:55
问题 Where do you like to catch exceptions and why? I'm interested in seeing where people find it useful to put their try/catch blocks in the hope that some general patterns might emerge. I'll post my two example answers in C++ but any language is fine. One location and reason per answer please. Thanks. 回答1: Don't catch anything that you are not prepared to and able to handle. So, have top-level exception handling in place to bomb the application the way you like on unexpected exceptions and then

Remove warning messages in PHP

喜夏-厌秋 提交于 2019-11-26 15:00:56
I have some PHP code. When I run it, a warning message appears. How can I remove/suppress/ignore these warning messages? You really should fix whatever's causing the warning, but you can control visibility of errors with error_reporting . To skip warning messages, you could use something like: error_reporting(E_ERROR | E_PARSE); PetPaulsen You can put an @ in front of your function call to suppress all error messages. @yourFunctionHere(); Karthik To suppress warnings while leaving all other error reporting enabled: error_reporting(E_ALL ^ E_WARNING); mohan.gade If you don't want to show

How to avoid isset() and empty()

人盡茶涼 提交于 2019-11-26 10:07:49
I have several older applications that throw a lot of "xyz is undefined" and "undefined offset" messages when running on the E_NOTICE error level, because the existence of variables is not explicitly checked using isset() and consorts. I am considering working through them to make them E_NOTICE compatible, as notices about missing variables or offsets can be lifesavers, there may be some minor performance improvements to be gained, and it's overall the cleaner way. However, I don't like what inflicting hundreds of isset() empty() and array_key_exists() s does to my code. It gets bloated,

Remove warning messages in PHP

谁说我不能喝 提交于 2019-11-26 04:06:51
问题 I have some PHP code. When I run it, a warning message appears. How can I remove/suppress/ignore these warning messages? 回答1: You really should fix whatever's causing the warning, but you can control visibility of errors with error_reporting(). To skip warning messages, you could use something like: error_reporting(E_ERROR | E_PARSE); 回答2: You can put an @ in front of your function call to suppress all error messages. @yourFunctionHere(); 回答3: To suppress warnings while leaving all other

How do I get PHP errors to display?

核能气质少年 提交于 2019-11-25 22:50:41
问题 I have checked my PHP init file ( php.ini ) and display_errors is set and also error reporting is E_ALL . I have restarted my Apache webserver. I have even put these lines at the top of my script, and it doesn\'t even catch simple parse errors. For example, I declare variables with a \"$\" and I don\'t close statements \";\" . But all my scripts show a blank page on these errors, but I want to actually see the errors in my browser output. error_reporting(E_ALL); ini_set(\'display_errors\', 1)

mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?

冷暖自知 提交于 2019-11-25 21:29:37
问题 In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error: Fatal error: Call to a member function bind_param() on a non-object in... Here is the code: global $mysqli; $stmt = $mysqli->prepare(\"SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?\"); $stmt->bind_param(\'i\', $cur_id); $stmt->execute(); $stmt->bind_result($uid, $desc); To check my query, I tried to execute the query via