Search code examples
phpcolorsstylespretty-printvar-dump

Colored var_dump() and errors


How can I set style to var_dump() function and PHP errors style, like on the next image?

enter image description here

enter image description here

At the moment I have next view of var_dump() (with <pre>var_dump(...)</pre>, without it will be all in one line) and just plain text for errors.

enter image description here

I searched something for PHP colored errors, var_dump styles, but could not find anything.

I used OpenServer as localhost, and on previous version I had same styles for errors, but now just plain text. Is it real to customize?


Solution

  • You get the colored output when you ínstall and enable Xdebug:

    Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types and places limits on the amount of array elements/object properties, maximum depth and string lengths. There are a few other functions dealing with variable display as well.

    You can enable/disable this with the ini setting xdebug.overload_var_dump

    By default Xdebug overloads var_dump() with its own improved version for displaying variables when the html_errors php.ini setting is set to 1. In case you do not want that, you can set this setting to 0, but check first if it's not smarter to turn off html_errors.

    Check the documentation for further information.

    Note that you do not want to have the Xdebug extension installed on a production server as it will significantly slow down code execution.