Jump to content

PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in

Recommended Posts



I see a problem in my error log:

[28-Feb-2021 17:56:34 Europe/Amsterdam] PHP Warning:  htmlspecialchars() expects parameter 1 to be string, array given in /home/XXX/public_html/var/cache/prod/smarty/compile/warehouselayouts_layout_full_width_tpl/a4/5e/c8/a45ec8b6e41f76c7af2e5ff1fb03cffacfb2ee57_2.file.product-prices.tpl.php on line 226

Line 226:

<span class="current-price"><span itemprop="price" class="product-price" content="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['product']->value['rounded_display_price'], ENT_QUOTES, 'UTF-8');?>
"><?php echo htmlspecialchars($_smarty_tpl->tpl_vars['product']->value['price'], ENT_QUOTES, 'UTF-8');?>

This is my product-prices.tpl file

 * 2007-2017 PrestaShop
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2017 PrestaShop SA
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA

    <div class="product-prices">
        {block name='product_reference'}
            {if $iqitTheme.pp_reference == 'title'}
            {if isset($product.reference_to_display) && $product.reference_to_display neq ''}
                <div class="product-reference">
                    <label class="label">{l s='Reference' d='Shop.Theme.Catalog'} </label>                    <span itemprop="sku">{$product.reference_to_display}</span>					<br />					<label class="label">{l s='Ean13' d='Shop.Theme.Catalog'}:</label>					<span itemprop="gtin13" content="{$product.ean13}">{$product.ean13}</span>

        {if $product.show_price}
        {if !$configuration.is_catalog}
            {block name='product_availability'}
                {if $product.show_availability && $product.availability_message}
                    <span id="product-availability"
                          class="badge {if $product.availability == 'available'} {if $product.quantity <= 0  && !$product.allow_oosp} badge-danger product-unavailable  {elseif $product.quantity <= 0  && $product.allow_oosp}badge-warning product-unavailable-allow-oosp {else}badge-success product-available{/if}{elseif $product.availability == 'last_remaining_items'}badge-warning product-last-items{else}badge-danger product-unavailable{/if}">
                  {if $product.availability == 'available'}
                      <i class="fa fa-check rtl-no-flip" aria-hidden="true"></i>
                  {elseif $product.availability == 'last_remaining_items'}
                      <i class="fa fa-exclamation" aria-hidden="true"></i>
                      <i class="fa fa-ban" aria-hidden="true"></i>
                      {if isset($product.available_date) && $product.available_date != '0000-00-00'}
                      {if $product.available_date|strtotime > $smarty.now}<span
                              class="available-date">{l s='until' d='Shop.Theme.Catalog'} {$product.available_date}</span>{/if}

        {block name='product_price'}
            <div class="{if $product.has_discount}has-discount{/if}"

                {if isset($product.seo_availability)}
                    <link itemprop="availability" href="{$product.seo_availability}"/>
                    <link itemprop="availability" href="https://schema.org/InStock"/>
                <meta itemprop="priceCurrency" content="{$currency.iso_code}">
                <meta itemprop="url" content="{$product.url}">

                    <span itemprop="price" class="product-price" content="{$product.rounded_display_price}">{$product.price}</span>
                    {if $product.has_discount}
                        <span class="product-discount">
                            {hook h='displayProductPriceBlock' product=$product type="old_price"}
                            <span class="regular-price">{$product.regular_price}</span>

                        {if $product.discount_type === 'percentage'}
                            <span class="badge badge-discount discount discount-percentage">-{$product.discount_percentage_absolute}</span>
                            <span class="badge badge-discount discount discount-amount">-{$product.discount_to_display}</span>

                        {if isset($product.specific_prices.to) && $product.specific_prices.to != '0000-00-00 00:00:00'}<meta itemprop="priceValidUntil" content="{$product.specific_prices.to}"/>{/if}

				                {block name='product_unit_price'}
                    {if $displayUnitPrice}
                        <p class="product-unit-price text-muted">{l s='(%unit_price%)' d='Shop.Theme.Catalog' sprintf=['%unit_price%' => $product.unit_price_full]}</p>

        {block name='product_without_taxes'}
            {if $priceDisplay == 2}
                <p class="product-without-taxes text-muted">{l s='%price% tax excl.' d='Shop.Theme.Catalog' sprintf=['%price%' => $product.price_tax_exc]}</p>

        {block name='product_pack_price'}
            {if $displayPackPrice}
                <p class="product-pack-price">
                    <span>{l s='Instead of %price%' d='Shop.Theme.Catalog' sprintf=['%price%' => $noPackPrice]}</span>

        {block name='product_ecotax'}
            {if $product.ecotax.amount > 0}
                <p class="price-ecotax text-muted">{l s='Including %amount% for ecotax' d='Shop.Theme.Catalog' sprintf=['%amount%' => $product.ecotax.value]}
                    {if $product.has_discount}
                        {l s='(not impacted by the discount)' d='Shop.Theme.Catalog'}

        {hook h='displayProductPriceBlock' product=$product type="weight" hook_origin='product_sheet'}

        <div class="tax-shipping-delivery-label text-muted">
            {if isset($configuration.taxes_enabled) && !$configuration.taxes_enabled}
                {l s='No tax' d='Shop.Theme.Catalog'}
            {elseif $configuration.display_taxes_label}
            {hook h='displayProductPriceBlock' product=$product type="price"}
            {hook h='displayProductPriceBlock' product=$product type="after_price"}
            {if $product.additional_delivery_times == 1}
                {if $product.delivery_information}
                    <span class="delivery-information">{$product.delivery_information}</span>
            {elseif $product.additional_delivery_times == 2}
                {if $product.quantity > 0}
                    <span class="delivery-information">{$product.delivery_in_stock}</span>
                    {* Out of stock message should not be displayed if customer can't order the product. *}
                    {elseif $product.quantity <= 0 && $product.add_to_cart_url}
                    <span class="delivery-information">{$product.delivery_out_stock}</span>
        {hook h='displayCountDown'}

Does anyone know a solution?


Best Regards,



Edited by vxmretail
extra info (see edit history)

Share this post

Link to post
Share on other sites
Posted (edited)

Like the error says function htmlspecialchars() is receiving an array instead of a string.

echo htmlspecialchars($_smarty_tpl->tpl_vars['product']->value['price'], ENT_QUOTES, 'UTF-8');


Troubleshooting this issue, lets create a new PHP file with just  the htmlspecialchars() function and a variable we know is 100% a string:

$variable['test'] = 'mystringvalue';
echo htmlspecialchars($variable['test'], ENT_QUOTES, 'UTF-8');

which output "mystringvalue", this way we know the function htmlspecialchars() is used correctly.

Next step is to check your variables, which of them is not a string?

Try to var_dump them both to see which one is a array instead of a string

echo var_dump($_smarty_tpl->tpl_vars['product']->value['price']);

echo var_dump($_smarty_tpl->tpl_vars['product']->value['rounded_display_price']);

One of these variables will be an array, resolve the issue and enjoy!

Edited by Crezzur (see edit history)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More