JUN 28 2018

PHP Parse error: syntax error, unexpected ‘[‘ in app/code/core/Mage/Checkout/Model/Type/Onepage.php on line 691

Problem description

Magento Onepage checkout page is blank after SUPEE-10752.
The following fatal PHP error thrown at Magento Onepage Checkout page after installing SUPEE-10752 patch:
PHP Parse error:  syntax error, unexpected '[' in app/code/core/Mage/Checkout/Model/Type/Onepage.php on line 691

Cause

Array de-referencing is used in the following line of code added in SUPEE-10752:
--- app/code/core/Mage/Checkout/Model/Type/Onepage.php
+++ app/code/core/Mage/Checkout/Model/Type/Onepage.php
@@ -688,6 +688,9 @@ class Mage_Checkout_Model_Type_Onepage
         Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
         $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
         $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
+        $passwordCreatedTime = $this->_checkoutSession->getData('_session_validator_data')['session_expire_timestamp']
+            - Mage::getSingleton('core/cookie')->getLifetime();
Support of array de-referencing is added in PHP 5.4, older versions (PHP 5.3) will throw fatal error like above on attempt of array de-referencing.

Solution

Make sure that you use PHP 5.4 version or newer. For older Magento versions (v.1.8.x.x and earlier, including 1.7.0.2), install PHP 5.4 compatibility patch and ask your host to upgrade your PHP version to 5.4.
Warning:It is required to install PHP 5.4 compatibility patch for older Magento versions prior to PHP version upgrade.

Alternatively, change the offending code in app/code/core/Mage/Checkout/Model/Type/Onepage.php by copying it into app/code/local/Mage/Checkout/Model/Type/Onepage.php and adding a temporary variable like below:
--- app/code/core/Mage/Checkout/Model/Type/Onepage.php
+++ app/code/core/Mage/Checkout/Model/Type/Onepage.php
@@ -688,6 +688,9 @@ class Mage_Checkout_Model_Type_Onepage
         Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
         $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
         $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
-        $passwordCreatedTime = $this->_checkoutSession->getData('_session_validator_data')['session_expire_timestamp']
+        $local_session_validator_data=$this->_checkoutSession->getData('_session_validator_data');
+        $passwordCreatedTime = $local_session_validator_data['session_expire_timestamp']

Posted in: Fatal errors

PHP Parse error: syntax error, unexpected ‘[‘ in app/code/core/Mage/Checkout/Model/Type/Onepage.php on line 691
7 votes, 5.00 avg. rating (98% score)
  • Angelo

    I have this problem but i don’t solve it.
    I use php5.5 and mag1.9.1
    I installed the patch but One page checkout with user logged and with compilation active doesn’t run.
    Now I modifiy file app/code/core/Mage/Checkout/Model/Type/Onepage.php and I create a new file in app/code/core/Mage/Checkout/Model/Type/Onepage.php… but nothing change.