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:
Screenshots
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
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.
Most helpful comment
Hello @polo195pl
This behavior is because
$product
is not an array any more but aProductLazyArray
, 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:I hope this will help you.