Notices, warnings and errors

2

There are several levels of error in PHP. By default, PHP outputs occurred errors into stdout (prints them like they're a part of the output content) and writes them into log file.

You can set a minimum level of errors you want to get reported with error_reporting function. To print all kind of issues you should use:

error_reporting(E_ALL); # Prints all errors, warnings and notices

You can also select which type of issues you want to get reported. They work like flags:

error_reporting(E_ERROR | E_WARNING); # Prints errors and warnings only

To disable all types of issues reporting do this:

error_reporting(0);

Error levels you should learn today:

E_ERROR   # Fatal error. PHP script execution will stop on that type of error.
E_WARNING # Non-fatal error. Error will be reported but PHP script will continue to execute.
E_PARSE   # Compile-time (or parsing-level) error. PHP script won't start at all.
E_NOTICE  # A sort of error that may be not really an error. That's up to the application.
E_ALL     # All types of issues.

You can also disable output of errors but still continue to log them:

ini_set('display_errors', 0);

You can suppress a report of a recoverable error in a single statement with @ prefix:

$content = @file_get_contents('so_such_file.txt'); # No report is generated
Lesson 11
Share this page:

Learning plan

Most common and useful PHP built-in functions
The next portion of things you should learn about PHP types
The second part of basics of PHP arrays
12. Notices, warnings and errors
Things you should know to configure error reporting properly
How to split PHP script into pieces and include them into each other
14. Operators
We should learn all PHP operators in details before we could continue
15. stdClass
The very basics of stdClass PHP class