How to debug an error in Zencart

By default Zencart disables all types of errors. Due to this if an error is encountered then all you would see is the “dreaded white page” and that is bad programming practice if you are developing in PHP. As PHP is a scripting language it stops execution as soon as it encounters an error due to which you will have a hard time debugging your application. You will not only waste your time and effort but also some of the hair left on your head. I know I did. Just joking!

You need to enable error reporting in your application during development and disable it when deploying it to the production server.

Open the includes/application_top.php file. Search for error_reporting and you will encounter a block of code as follows

if (defined('STRICT_ERROR_REPORTING') && STRICT_ERROR_REPORTING == true) {
  @ini_set('display_errors', '1');
  error_reporting(E_ALL);
} else {
  error_reporting(0);
}

The code checks for a constant STRICT_ERROR_REPORTING and if its true then it enables error_reporting and also displays the errors on the web page. If its false (by default) then error_reporting is disabled. You need to define the constant as its not present in the code. Just add the following line before the if block and now the block of code will look like.

define('STRICT_ERROR_REPORTING', true);
if (defined('STRICT_ERROR_REPORTING') && STRICT_ERROR_REPORTING == true) {
  @ini_set('display_errors', '1');
  error_reporting(E_ALL);
} else {
  error_reporting(0);
}

Now when you run the website it will display all notices, warnings and errors. Don’t get scared if you see a lot of lines come up on the web page. This will help you to debug the issue and correct it. This also helps you in writing good code and provides you the opportunity to make the code as error free as possible.

Hope the above helps

Leave a Comment