-4

Parse error: syntax error, unexpected ':', expecting '{' in /home/karencom/public_html/wp-content/plugins/woocommerce/woocommerce.php on line 57

Below is the code

function wc_get_container() : \Psr\Container\ContainerInterface {
    return $GLOBALS['wc_container'];
}

How do I solve this, I've tried for hours to change the ":" to "{" but it returns another error:

Parse error: syntax error, unexpected '{' in /home/karencom/public_html/wp-content/plugins/woocommerce/woocommerce.php on line 57

jasie
  • 2,192
  • 10
  • 39
  • 54
  • 1
    That code looks totally fine to me - which version of PHP do you use? Also, if this is unmodified code of WooCommerce, why not ask their support for help? – Nico Haase Aug 18 '22 at 11:44
  • Most likely you're using a lower version of PHP than the code requires. The return type declaration is only allowed since PHP 7.0 – aynber Aug 18 '22 at 11:50
  • Hi Nico, I'm using PHP: 7.0, and thank you for the idea. Lemme ask the WooCommerce support. – Michael Ndula Aug 18 '22 at 11:52

1 Answers1

0

PHP 7.0, which you use according to a comment, is horribly outdated. All kinds of official support have ended more than three years ago in Dec 2018. Before blaming WooCommerce, you could update your server.

Even if you haven't told which version of WooCommerce you use, the official document for server requirements lists a minimum version of PHP 7.2.

Nico Haase
  • 11,420
  • 35
  • 43
  • 69