handling PHP error
Moderator: General Moderators
handling PHP error
I am still on my second month of studying and programming with PHP. Realizing that locating bugs or errors is very time consuming, I would to ask anyone who can share their technique in "Handling PHP Error" so i could display customized messages rather that just sometimes looking at blank browser window.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Have you tried?
This will report all errors.
Code: Select all
<?php
error_reporting(E_ALL ^ E_NOTICE);
?>yes, you will need to edit the php.ini file to turn this on. if there's a parse error, turning the ini_set("display... will still show a blank page
either change it in the ini (preferred) or set the change in a .htaccess file
either change it in the ini (preferred) or set the change in a .htaccess file
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
i really delved into php.ini and it's worthy! what i noticed that the value of display_errors was indeed 'off'. after changing it to "on" and reboot the server, i was glad that errors are now reported by experimenting on removing a ";" semicolon on a single php statement as expected there was parse error! but on another page a notice was diplayed. whats the meaning of "undefined index.."?
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
at times when you make calls to files like
Code: Select all
<?php
$content = "hello";
#if you make this on your local machine, not on the server where text.txt exists, PHP will say undefined index, ##cuz it cannot find text.txt
$fp = fopen("text.txt", 'a');
fwrite($fp, $content);
fclose($fp);
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You are referencing part of an array that doesn't exist, e.g. you'd get that error forjoboy wrote:whats the meaning of "undefined index.."?
Code: Select all
$array = array('test' => 1, 'test2' => 2);
echo $array['test3'];- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
DO NOT LEAVE DISPLAY ERRORS ON FOR PRODUCTION ENVIRONMENTS! Hope that didn't sound too loud, but for security, develop with display_errors On but turn it off for production. Also, if you set your error_reporting level to E_ALL you will see all kinds of information about your code (very useful when developing, but again, you might want to turn it down a notch or two for production).joboy wrote:i really delved into php.ini and it's worthy! what i noticed that the value of display_errors was indeed 'off'. after changing it to "on" and reboot the server, i was glad that errors are now reported by experimenting on removing a ";" semicolon on a single php statement as expected there was parse error! but on another page a notice was diplayed. whats the meaning of "undefined index.."?
One of the most annoying errors is when it's the client experiencing them and all they can say is "my site's broken" and no matter how hard you try, you can't recreate the problem.
There are a couple of ini settings that can help out:
log_errors [bool]
error_log [filename]
These will log any PHP errors to a file of your choice which can be very handy in a production environment.
There are a couple of ini settings that can help out:
log_errors [bool]
error_log [filename]
These will log any PHP errors to a file of your choice which can be very handy in a production environment.