How to debug PHP in the MAMP?

2019-01-29 10:26发布

问题:

I'm using MAMP on Windows to start a web server for my WordPress website. I want to debug some PHP code (at least write variable values to log/browser console/anywhere else). I've tried to write in PHP source this:

debug_to_console($args);
var_dump($args);
error_log(print_r($args,true));

And looked for the result in MAMP/logs/phperror.log. But it doesn't write anything.

How to debug PHP code in this case?

回答1:

If you want to debug WordPress, just turn on debug mode. Add this into your wp-config file instead of this one define( 'WP_DEBUG', false );

Add this code:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Next step is just using this one:

error_log(print_r($args,true));

Your $args you'll see in the {your-local-website-path}/wp-content/debug.log file