PHP can display errors in text or HTML format, depending on the
Plain text output: (HTML format differs between implementations)
NOTE: If you have error reporting disabled in php.ini and enable it during runtime, some errors (such as parse errors) won't be displayed, because they occured before the runtime setting was applied.
The common way to handle
error_reporting is to enable it fully with
E_ALL constant during the development, and to disable publicly displaying it with
display_errors on production stage to hide the internals of your scripts.
var_dump function allows you to dump the contents of a variable (type and value) for debugging.
Error Reporting (use them both)
It is imperative that
phpinfo is only used in a development environment. Never release code containing
phpinfo into a production environment
Having said that, it can be a useful tool in understanding the PHP environment (OS, configuration, versions, paths, modules) in which you are working, especially when chasing a bug. It is a simple built in function:
It has one parameter
$what that allows the output to be customized. The default is
INFO_ALL, causing it to display all information and is commonly used during development to see the current state of PHP.
You can pass the parameter
INFO_* constants, combined with bitwise operators to see a customized list.
You can run it in the browser for a nicely formatted detailed look. It also works in PHP CLI, where you can pipe it into
less for easier view.
When working with various libraries and their associated requirements, it is often necessary to know the version of current PHP parser or one of it's packages.
This function accepts a single optional parameter in the form of extension name:
phpversion('extension'). If the extension in question is installed, the function will return a string containing version value. However, if the extension not installed
FALSE will be returned. If the extension name is not provided, the function will return the version of PHP parser itself.
Xdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
There are some nice features in this tool:
- stack traces on errors
- maximum nesting level protection and time tracking
- helpful replacement of standard
var_dump()function for displaying variables
- allows to log all function calls, including parameters and return values to a file in different formats
- code coverage analysis
- profiling information
- remote debugging (provides interface for debugger clients that interact with running PHP scripts)
As you can see this extension is perfectly suited for development environment. Especially remote debugging feature can help you to debug your php code without numerous var_dump's and use normal debugging process as in
Usually installing of this extension is very simple:
And activate it into your php.ini:
In more complicated cases see this instructions
When you use this tool you should remember that:
XDebug is not suitable for production environments