Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Securing PHP Code
 
Article Index
Securing PHP Code
Page 2
Page 3
Page 4
Page 5
 

Maximum Error

Let's get back to the example with the globals once more. In the first faulty code, all could have been avoided if there was a warning when uninitialized variables are used. Unfortunately, the standard error reporting value in php.ini is the following:

error_reporting = E_ALL & ~E_NOTICE

That means that all errors are reported, but no notices. In many cases, this is a bad idea. If you access an uninitialized variable, this sometimes happens as intended; however, at other times this could be a typo. Therefore, tune error_reporting to maximum reporting. Nobody likes error messages, but it should be your primary goal to write code that creates zero error messages and warnings. Here is the appropriate setting:

error_reporting = E_ALL

Again, think of providers that set error_reporting at their will. You might work with E_ALL & ~E_NOTICE at home, but your hoster could use E_ALL, which would result in ugly notices within your code. To be compatible with all settings of error_reporting, set your system to E_ALL.

TIP

If you do not want to use maximum error reporting (or if you have inherited a lot of code and cannot change it over the weekend), the PHP function error_reporting() lets you set error reporting on a per-page basis.


New in PHP 5 is the error level E_STRICT (value: 2048). This is even stricter than E_ALL and includes additional warnings when deprecated PHP functions are used.

When you are finished with an application and want to go live with it, you should disable error reporting completely. But that does not mean that you should change the configuration value for error_reporting; instead, you should tell PHP not to send any errors to the client:

display_errors = Off

However, you do want these errors to appear in your Web server's error log; therefore, set log_errors to On.



Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Natural 327
Statistic


Last Post

 
Top! Top!