PHP 7.2 error "[] operator not supported for strings"

  • Posts: 200
  • Thank you received: 75
5 years 4 months ago #300868

-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9.0
-- PHP version -- : 7.2

Hi,

we tried updating our PHP version from 7.0 to 7.2, but we receive a fatal error "[] operator not supported for strings" on every product listing page where a product has variants, also with the latest Hikashop version 4.0.1 [1811151423] and with default protostar template.
The call stack indicates the error occurs in the administrator\components\com_hikashop\classes\currency.php file on line 956.

We haven't made any changes or customisations, but it seems slightly strange why no one else would have noticed this before. Thanks for looking into it and for any help.

Kind regards,

Please Log in or Create an account to join the conversation.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
5 years 4 months ago #300906

Hello,

Line 956 is

$products[$k]->variant_ids[] = $variant->product_id;
But the variable $products is an array and the entry variant_ids is also an array.
Unfortunately, I don't know how you have a string while you need to have an array.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
5 years 4 months ago #300933

Hi,

ok, but clearly something is not working correctly and like I stated, we haven't made any customizations in any core files, in fact we just updated from 3.5.1 to 4.0.1 so all files are as delivered by the update. So what can we do to figure out what is causing this?

Kind regards,

Please Log in or Create an account to join the conversation.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
5 years 4 months ago #300934

Hello,

You can activate the debug mode in order to have the full call stack ; it will help to understand what function called the currency class and maybe understand why the content is not what it should.
Afterwards, it could be useful to perform a print of the products array, to see what is the content of the variant_ids.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
5 years 4 months ago #300995

Hi,

attached is a screenshot of the full call stack, hopefully it can provide some additional insight into the problem.
If we print the variant_ids they appear normal to us, for example: 220,221,222,223
However, if we print $products[$k]->variant_ids[] it appears the first element is null/empty and we think this is the cause of the error, because it falls through the check on line 954 since it is set, only null, and so on line 956 you assume it is an array while it is not, thus causing the error.

We have no idea so far why this first element is empty, and why strangely enough we seem to be the only one having this issue even though we don't have any customizations and use exactly the same code as everybody else, but if we change line 954 in currency.php from:

if(!isset($products[$k]->variant_ids))
      $products[$k]->variant_ids = array();
to:
if(!isset($products[$k]->variant_ids) || $products[$k]->variant_ids==null)
      $products[$k]->variant_ids = array();

this will also re-initialise the empty variant_ids as an array and everything seems to work ok.
However, this seems more of a hack and doesn't fix the cause of the problem, so any further help with that is much appreciated. Thanks.

Kind regards

Attachments:
Last edit: 5 years 4 months ago by GW.

Please Log in or Create an account to join the conversation.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
5 years 4 months ago #301002

Hello,

In such case, I would suggest the usage of

if(empty($products[$k]->variant_ids))
      $products[$k]->variant_ids = array();

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
5 years 4 months ago #301073

Ok, will this also be added on your end, or do we have to re-insert this code every time we update in future?

Thanks again.

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
5 years 4 months ago #301078

Hi,

If you can confirm that the suggestion proposed by Jerome solved the issue for you, we'll be happy to add it on our end for the next version.

Please Log in or Create an account to join the conversation.

  • Posts: 200
  • Thank you received: 75
5 years 4 months ago #301097

That's great, yes Jerome's suggestion works fine, no more PHP errors anywhere.

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

  • Posts: 2
  • Thank you received: 0
4 years 8 months ago #309657

I bought the Hikshop version 4.2.1 just a week ago, and I am facing issues on the product listing I made (I get a blank page with just the word "error" on the front end, when I display the debugging, it says: Error: [] operator not supported for strings: [] operator not supported for strings

Which is how came to this forum article.

If I still need to adapt something, can someone help me with precise instructions (which file to update in which directory and on which line?)
Thanks!!

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
4 years 8 months ago #309658

Hi,

The patch we discussed here has been added to HikaShop several versions ago.
So your issue is different.
When you activate the debug, you should have a callstack with more information on which lines of which files lead to that error.
Could you provide the full debug information ? That would help us understand how you got that error.
If you don't have the callstack, could you try with the default template of Joomla ? Then you should get the callstack with the information we need.

Please Log in or Create an account to join the conversation.

  • Posts: 2
  • Thank you received: 0
4 years 8 months ago #309678

The full context errors read:

With template jd_miami
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Color has a deprecated constructor in /home/xxxx/templates/jd_miami/features/color.php on line 11
Error: [] operator not supported for strings: [] operator not supported for strings

with template Beez3
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/xxxx/administrator/components/com_seoboss/lib/Snoopy.class.php on line 651

The page is rendered as expected.


with template jd_fago
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/xxxx/administrator/components/com_seoboss/lib/Snoopy.class.php on line 651

The page is rendered as expected.

Conclusion: use jd_fago on the hikashop menu items?

Thanks for pointing me in the right direction.

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
4 years 8 months ago #309682

Hi,

Then it means that you have an issue with a view override in your template. You have to check the folder /home/xxxx/templates/jd_miami/html/com_hikashop/
There, you'll have subfolders with view override files in them. You can rename them one by one to deactivate them and find which view override is creating the problem.
Then, you can leave the view override file creating the issue renamed and contact your template provider to notify them of the issue.

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum