Published: March 31, 2021
Last updated:

PHP Parse error: syntax error, unexpected ‘:’, expecting ‘;’ or ‘{‘ in app/code/core/Mage/Core/Model/Cookie.php on line 183

The following fatal error logged after upgrade to OpenMage with PHP5.6:

PHP Parse error:  syntax error, unexpected ':', expecting ';' or '{' in app/code/core/Mage/Core/Model/Cookie.php on line 183
Errors parsing app/code/core/Mage/Core/Model/Cookie.php


Cause

The cause is PHP7 type declaration in getSameSite() function added in commit 26b9eee1275b882dac0a84adcf8e22ca643afb61 merged into 1.9.4x tree in December 2020 and included in v19.4.10 release:
    public function getSameSite(): string
    {
        $sameSite = Mage::getStoreConfig(self::XML_PATH_COOKIE_SAMESITE, $this->getStore());
        if (is_null($sameSite)) {
            return 'None';
        }
        return (string)$sameSite;
    }
Type declaration is not supported in older PHP versions.

Solution

Switch your PHP version to PHP 7.3+ (PHP7.0 is minimal version and PHP7.3 is current recommended version) prior to OpenMage upgrade.

If changing PHP version is not possible due to some reason you can temporarily remove the type declaration in that function to let store run with PHP5.6 and re-apply it back when PHP/OS upgrade issues are sorted out:
diff --git a/app/code/core/Mage/Core/Model/Cookie.php b/app/code/core/Mage/Core/Model/Cookie.php
index 7e29814..5ee92e9 100644
--- a/app/code/core/Mage/Core/Model/Cookie.php
+++ b/app/code/core/Mage/Core/Model/Cookie.php
@@ -180,7 +180,7 @@ class Mage_Core_Model_Cookie
      *
      * @return string
      */
-    public function getSameSite(): string
+    public function getSameSite()
     {
         $sameSite = Mage::getStoreConfig(self::XML_PATH_COOKIE_SAMESITE, $this->getStore());
         if (is_null($sameSite)) {


Note, there were a few other PHP5.6 incompatible changes in OpenMage 1.9.4.x tree. There is a php56-compat fork with up-to-date changes merged with mainstream 1.9.4.x tree.



Posted in: Fatal errors

1 vote, 5.00 avg. rating (85% score)