debug

PHP Logo

Debugging And Testing PHP With assert()

8th August 2021 - 16 minutes read time

PHP has a built in debugging and testing tool called assertions, which is essentially the assert() function and a few configuration options.

With this feature you can add additional checks to your application whilst you are developing it so that when you deploy to production you can be sure that things will run correctly. It is simple to run and allows you to embed testing code within your production code without having an adverse effect on performance.

I've seen the use of assert() in a couple of open source PHP projects, but had not really dug into how it works or what it does. As it turns out, assert() is actually very useful and can also be found in other languages like C/C++, Python and JavaScript.

WordPress Logo

Logging Errors In WordPress

21st June 2011 - 3 minutes read time

To debug WordPress many sites will tell you to add the WP_DEBUG setting on its own to your wp-config.php file, but this can be quite harmful as many server configurations will start showing PHP errors and warning messages on your site pages. Most sites will also log any errors to some form or error log, but this isn't always the best place for them to go.

It is possible to add a set of debug options that will allow WordPress to log any errors or warnings to a file. Open up your wp-config.php file and add the following lines of code above the line that says "/* That's all, stop editing! Happy blogging. */". Any changes to this file should always go above this line so that you can keep track of them.