New Perspectives On Web Design

(C. Jardin) #1
By Paul Tero CHAPTER 8

is for parsing or syntax errors and has the value 4. These values are all
powers of two and can be safely added together. So the number 7 means
that all three types of errors should be reported, as E_ERROR + E_WARNING +
E_PARSE = 7. A value of 5 will only report E_ERROR + E_PARSE.
In reality, there are 16 types of errors from 1 for E_ERROR to 16384
for E_USER_DEPRECATED. You can type “30719 in binary” into Google and
it will give you the binary equivalent: 0b111011111111111. This means
that all errors are switched on except the twelfth, which is E_STRICT. This
particular setup has also been given a constant E_ALL = EERROR + E
WARNING + E_PARSE + etc = 30719. From PHP version 5.4.0, E_ALL is actually
32767 which includes all the errors include E_STRICT.
If your error_reporting setting is 0, then no errors will show up in the
log file. You can change this setting in the file php.ini, but then you have
to restart Apache to make it have an effect. An easier way to change this
setting in Apache is to add a line in a file called .htaccess in your document
root: php_value error_reporting 30719.
Or you can do that on the command line, using the double arrow which
appends to an existing file or creates the file if it doesn’t exist:


$ echo "php_value error_reporting 30719" >> .htaccess
$ echo "php_value log_errors On” >> .htaccess


Refresh your erroneous Web page. If there is a PHP error in your page it
should now show up in the error log. You can grep the log for all PHP errors:


grep PHP /var/www/vhosts/smashingmagazine.com/statistics/logs/error_log
[Sun May 12 18:19:09 2013] [error] [client 81.106.118.59] PHP Notice:
Undefined variable: total in /var/www/vhosts/smashingmagazine.com/htt-
pdocs/products/view.php on line 10...


If you have referenced variables or array indices before assigning
them values, you may see thousands of PHP notices like the one above.
It happens when you do things like <? $total = $total + 1 ?> without

Free download pdf