Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development WordPress Header and Footer Templates Porting existing headers and footers into WordPress

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Debugging PHP

I had some problems with the code in this section and had a job debugging the PHP. I had made a few spelling errors which were hard to spot. I wondered if there is a good method for debugging PHP code. It does not seem as straight forward as debugging JS, as in this instance if the code doesn't work nothing appears on screen and no errors show up in the developer console either.

1 Answer

Zachary Green
Zachary Green
16,359 Points

you can turn on errors in php in you script which outputs html with the text of the error. http://php.net/manual/en/function.error-reporting.php

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Also I discovered that by default WordPress has error reporting switched off

define('WP_DEBUG', false);

If you change this line to the following it should report errors: define('WP_DEBUG', true);

In addition you can log the errors instead define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors', 0);

Might be an idea for the track on WordPress development to explain this early on to help developers. Obviously debugging should be switched off when the project goes live. There's more on WordPress debugging here: http://css-tricks.com/snippets/wordpress/turn-on-wordpress-error-reporting/