Implementation of Debugging Tools with PrestaShop

By Alain Folletete - Lead Developer PrestaShop

During the development stage, developers often need to « debug » by posting, for instance, the status of a variable at any given time (t).

Any developer will tell you that all you need to do is use « var_dump() », « print_r() », « die() »…

The above methods are effective but PrestaShop offers other convenient debugging tools, and these are what we present here.

The tools

The functions p() (or ppp()) and d() (or ddd())

Two functions are available in PrestaShop. They make it possible to display a variable’s content very quickly : p(), ppp(), d(), ddd().

The difference between p() (or ppp()) and d() (or ddd())

P() and d() bring up the same result, however d() adds a die() at the end, thereby interrupting the processing.

Ppp() does the same as p(), as is also the case for ddd(). This function exists because it is sometimes simpler to search ppp() in the code than p(), for instance during a debugging.

Below is the result of a request for the d() method with a variable containing a Product-type object :

Product Object
[tax_name] => deprecated
[tax_rate] => 19.6
[id_manufacturer] => 1
[id_supplier] => 1
[id_category_default] => 3
[manufacturer_name] => Apple Computer, Inc
[supplier_name] => AppleStore
[name] => iPod Nano
[specificPrice] => Array
[id_specific_price] => 1
[id_specific_price_rule] => 0
[id_cart] => 0
[id_product] => 1
[id_shop] => 0
[id_group_shop] => 0
[id_currency] => 0
[id_country] => 0
[id_group] => 0
[id_customer] => 0
[id_product_attribute] => 0
[price] => 0.000000
[from_quantity] => 1
[reduction] => 0.050000
[reduction_type] => percentage
[from] => 0000-00-00 00:00:00
[to] => 0000-00-00 00:00:00
[score] => 32

[out_of_stock] => 0
[depends_on_stock] =>

The advantage of p() and d() compared to print_r:

They allow for a proper formatting of the debugging content (by adding an opening and ending "pre" tag and a die() for the d() call).
On top of this, p() and d() are methods that save a considerable amount of time by avoiding having to reinvent the wheel for every development.

Good to know

Edit your config.inc.php file

During the debugging process, do not forget to modify your config.inc.php file by replacing :

/* Debug only */
@ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);


/* Debug only */
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);

This will allow you to display PHP and SQL errors.

The exceptions

As of the 1.5 version of PrestaShop which is already available in beta version, exceptions are now implemented.

Exception types

  • PrestaShopException : General Exception
  • PrestaShopDatabaseException : Exception concerning database
  • PrestaShopModuleException : Exception concerning module
  • PrestaShopPaymentException : Exception concerning payment

Every 2 weeks, get the best ecommerce tips and latest trends in your inbox.

By submitting this form, I agree to the data entered being used by PrestaShop S.A for sending newsletters and promotional offers. You can unsubscribe at any time by using the link in the emails sent to you. Learn more about managing your data and rights.

These articles may interest you