Tuesday, 1 August 2017

How to Use Xdebug for Advanced PHP Debugging


You could just debug your PHP code using functions such as error_log, print, and var_dump, (and to be honest we’ve all done it, a lot!), but sometimes they just aren’t enough, and can actually slow you down while developing. There must be a better way, surely?! Enter Xdebug, the rather awesome debugging and profiling tool for PHP.
In this post, I’ll take you through why Xdebug is amazing, getting it setup, how to use it, get the most out of it it, and some neat advanced uses all to make your life easier.
You can thank me later (in the comments)
How Xdebug Changed My Life
A few years ago I didn’t know debuggers existed, had never heard of Xdebug, and was quite happy using a function I’d cobbled together pinched from Stack Overflow in all my WordPress sites for debugging:
if ( ! function_exists( ‘_log’ ) ) {
function _log( $message ) {
if ( WP_DEBUG === true ) {
if ( is_array( $message ) || is_object( $message ) ) {
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
}
It was all I thought I needed until someone introduced me to Xdebug and
Source: https://managewp.org/articles/15759/how-to-use-xdebug-for-advanced-php-debugging




source https://williechiu40.wordpress.com/2017/08/01/how-to-use-xdebug-for-advanced-php-debugging/

No comments:

Post a Comment