Prestashop: var_dump show to much data 1.7.5

Created on 12 Jan 2019  路  7Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
When we make a vardamp or print_r some variable we have for examples output like: "array(6) { ["title"]=> string(0) "" ["canonical"]=> NULL ["meta"]=> array(4) { ["title"]=> string(47) (...)" but when i try made {$product|@var_dump} or {$product|@print_r} i have a lot's of data for examples: strings from admin dashobard, translations from diffrent parts of system and a lots of more (looks like a var_dump full shop)

To Reproduce
Steps to reproduce the behavior:

  1. Go to themes/your_theme/catalog/produc.tpl
  2. type {$product|@var_dump} or {$product|@print_r}
  3. See result

Screenshots
image

Additionnal information
PrestaShop version: 1.7.5 from 1.7.4.3 on fresh install i have that same problem
PHP version: 7.0.33

1.7.5.0 Bug FO Major No change required Products Theme & logo

Most helpful comment

Hello @polo195pl

This behavior is because $product is not an array any more but a ProductLazyArray, it includes more data and logic than the former array
(see https://github.com/PrestaShop/PrestaShop/blob/develop/src/Adapter/Presenter/Product/ProductLazyArray.php for more details)

If you need to display the initial product array (for debug) you can use the jsonSerialize method, here is how you can use it in your smarty template:

{$product->jsonSerialize()|@var_dump}

I hope this will help you.

All 7 comments

How about ditching the @ and just try $product|var_dump?

@rdy4ever that same

oh, look at this @jocel1 :D

Hi @polo195pl,

Thanks for your report.
I manage to reproduce the issue with PS1.7.5.0.
When I add this line code {$product|@var_dump} in the /Project_PrestaShop/themes/classic/templates/catalog/product.tpl, I have a lot of data.
1750.pdf
I tried with PS1.7.4.4, I have a lot of data, but there are no strings from the admin dashboard, translations.
1744.pdf
Thanks!

Hello @polo195pl

This behavior is because $product is not an array any more but a ProductLazyArray, it includes more data and logic than the former array
(see https://github.com/PrestaShop/PrestaShop/blob/develop/src/Adapter/Presenter/Product/ProductLazyArray.php for more details)

If you need to display the initial product array (for debug) you can use the jsonSerialize method, here is how you can use it in your smarty template:

{$product->jsonSerialize()|@var_dump}

I hope this will help you.

Ok thx all :)

@jolelievre its ok BUT if PrestaShop want to use LazyArray maybe the good point is used it as default? If in the future other variables also use LazyArray, I think that would be a good solution. On the other way, using methods of some objects directly in tpls is a reversing of the development of the project, not its development.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChineseNorris picture ChineseNorris  路  64Comments

ninefingersodnd picture ninefingersodnd  路  51Comments

onlinedhlx picture onlinedhlx  路  66Comments

photinia73 picture photinia73  路  59Comments

e-perrodon picture e-perrodon  路  69Comments