Networking, Programming and Graphics - Tutorials
ONLINEHOWTO.net Tutorials Category

PHP Errors, Warning, Notices

Type: Code Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Level: Beginner Networking, Programming and Graphics - Tutorials 
Networking, Programming and Graphics - Tutorials
Date: 2010-Feb-03
Networking, Programming and Graphics - Tutorials
Visited: 470 times
Networking, Programming and Graphics - Tutorials
Rating: Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Published: Ivory Morhuld

Did you receive this kind of PHP errors or something similar ?

Parse error: syntax error, unexpected T_ECHO in ...

Parse error: syntax error, unexpected ')'

Parse error: syntax error, unexpected '>', expecting T_VARIABLE or '$


When you are developing an PHP application of course you can make pass some errors which will malfunction the functionality of your application and you have to debug it. It is a good practice to trace this errors, to handle them and to repair. This can be done in entire developing process, by some testers after main development deadline or by the end users by sending bug reports which can be fixed in next versions of the application.

There are several types of errors in PHP. Depending of the type you can set some parameters which errors to be displayed, and for which not.

First you have to set 'display_errors' parameter which global affect all type of errors to display him or not to display anything. It is good to turn on this parameter while developing and to turn off when the application is ready and already works for the end users. The 'display_errors' parameter can be set trough PHP.INI, by '.htaccess' file or within the current application with:
<?php
ini_set
('display_errors'1);
?>
Next parameter which you have to set is 'error_reporting'.

<?php
error_reporting(E_ALL);
?>

error_reporting() can accept one value and exactly this value will set which kind of errors will be reported. Please see the next example:
<?php
error_reporting
(E_ALL);                // all problems will be reported
error_reporting(E_ERROR E_PARSE);    // major problems
error_reporting(E_ALL & ~E_NOTICE);    // all problems without notices
?>
In next table I will show you all PHP error types, their order with their value levels for using it with error_reporting() and their descriptions.
PHP Error Types

Value

Constant

Description

Catchable

1

E_ERROR

Nonrecoverable error

No

2

E_WARNING

Recoverable error

Yes

4

E_PARSE

Parser error

No

8

E_NOTICE

Possible error

Yes

16

E_CORE_ERROR

Like E_ERROR but generated by the PHP core

No

32

E_CORE_WARNING

Like E_WARNING but generated by the PHP core

No

64

E_COMPILE_ERROR

Like E_ERROR but generated by the Zend Engine

No

128

E_COMPILE_WARNING

Like E_WARNING but generated by the Zend Engine

No

256

E_USER_ERROR

Like E_ERROR but triggered by calling trigger_error( )

Yes

512

E_USER_WARNING

Like E_WARNING but triggered by calling trigger_error( )

Yes

1024

E_USER_NOTICE

Like E_NOTICE but triggered by calling trigger_error( )

Yes

2047

E_ALL

Everything except E_STRICT

N/A

2048

E_STRICT

Runtime notices in which PHP suggests changes to improve code quality (since PHP 5)

N/A

Rate this tutorial:                    
Post Comment

Need a specific tutorial? Do not hesitate and submit a request!
Your e-mail: