Page 1 of 2

[SOLVED] - trying to access array offset on value of type bool

Posted: Sun Apr 26, 2020 5:03 am
by emadrazanmay
Hi guys
opencart version : 2.3.0.2
php version :7.4.5
i got this error on checkout page:

Code: Select all

trying to access array offset on value of type bool in system/storage/modification/catalog/controller/startup/startup.php on line 171
the code responsible for this error is :

----------------------------------------------

Code: Select all

        if (isset($this->session->data['shipping_address'])) {
		$this->tax->setShippingAddress($this->session->data['shipping_address']['country_id'], $this->session->data['shipping_address']['zone_id']);
	} elseif ($this->config->get('config_tax_default') == 'shipping') {
		$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
	}
----------------------------------------------
code in line "171" is :
----------------------------------------------

Code: Select all

$this->tax->setShippingAddress($this->session->data['shipping_address']['country_id'], $this->session->data['shipping_address']['zone_id']);
----------------------------------------------
thanks for the help

Re: trying to access array offset on value of type bool

Posted: Sun Apr 26, 2020 6:05 am
by straightlight
See if the following could solved the issue for this version of PHP since it is still quite recent:

replace:

Code: Select all

if (isset($this->session->data['shipping_address'])) {
with:

Code: Select all

if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {

Re: trying to access array offset on value of type bool

Posted: Sun Apr 26, 2020 6:29 am
by emadrazanmay
yes it solved the problem
thank you straightlight for the great help

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Sat May 16, 2020 8:00 am
by aaron1988
This also helped me fix the issue for PHP 7.4 :) fantastic job.

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Thu Jun 04, 2020 10:17 pm
by dashingwebtech
This solution is really solve my issue. Its very irritating when any error occurred in live server.
So big thank you @straightlight

Dashingwebtech

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Thu Jun 04, 2020 10:38 pm
by straightlight
dashingwebtech wrote:
Thu Jun 04, 2020 10:17 pm
This solution is really solve my issue. Its very irritating when any error occurred in live server.
So big thank you @straightlight

Dashingwebtech
No problem. This fix as already been added in the pre-release version.

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Mon Jun 08, 2020 8:26 pm
by 5miffy
Thanks @straightlight for that fix.
I enabled PHP7.4 on an Opencart 3 site and the error was bugging the hell out of me until I used your suggestion!

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Tue Jul 28, 2020 7:31 pm
by IT beheerder KIK
This also helped me. Thanks a lot!

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Fri Aug 21, 2020 9:59 pm
by gerstavros
Solution worked, thanks

Code: Select all

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

OK

<b>Notice</b>: Trying to access array offset on value of type bool in <b>/var/www/site/html/catalog/controller/startup/startup.php</b> on line <b>166</b><b>Notice</b>: Trying to access array offset on value of type bool in <b>/var/www/site/html/catalog/controller/startup/startup.php</b> on line <b>166</b>{"country_id":"2","name":"Albania","iso_code_2":"AL","iso_code_3":"ALB","address_format":"","postcode_required":"0","zone":[{"zone_id":"33","country_id":"2","name":"Berat","code":"BR","status":"1"},{"zone_id":"34","country_id":"2","name":"Bulqize","code":"BU","status":"1"},{"zone_id":"35","country_id":"2","name":"Delvine","code":"DL","status":"1"},{"zone_id":"36","country_id":"2","name":"Devoll","code":"DV","status":"1"},{"zone_id":"37","country_id":"2","name":"Diber","code":"DI","status":"1"},{"zone_id":"38","country_id":"2","name":"Durres","code":"DR","status":"1"},{"zone_id":"39","country_id":"2","name":"Elbasan","code":"EL","status":"1"},{"zone_id":"41","country_id":"2","name":"Fier","code":"FR","status":"1"},{"zone_id":"42","country_id":"2","name":"Gjirokaster","code":"GJ","status":"1"},{"zone_id":"43","country_id":"2","name":"Gramsh","code":"GR","status":"1"},{"zone_id":"44","country_id":"2","name":"Has","code":"HA","status":"1"},{"zone_id":"45","country_id":"2","name":"Kavaje","code":"KA","status":"1"},{"zone_id":"40","country_id":"2","name":"Kolonje","code":"ER","status":"1"},{"zone_id":"48","country_id":"2","name":"Korce","code":"KO","status":"1"},{"zone_id":"49","country_id":"2","name":"Kruje","code":"KR","status":"1"},{"zone_id":"47","country_id":"2","name":"Kucove","code":"KC","status":"1"},{"zone_id":"50","country_id":"2","name":"Kukes","code":"KU","status":"1"},{"zone_id":"46","country_id":"2","name":"Kurbin","code":"KB","status":"1"},{"zone_id":"52","country_id":"2","name":"Lezhe","code":"LE","status":"1"},{"zone_id":"51","country_id":"2","name":"Librazhd","code":"LB","status":"1"},{"zone_id":"53","country_id":"2","name":"Lushnje","code":"LU","status":"1"},{"zone_id":"54","country_id":"2","name":"Malesi e Madhe","code":"MM","status":"1"},{"zone_id":"55","country_id":"2","name":"Mallakaster","code":"MK","status":"1"},{"zone_id":"56","country_id":"2","name":"Mat","code":"MT","status":"1"},{"zone_id":"57","country_id":"2","name":"Mirdite","code":"MR","status":"1"},{"zone_id":"58","country_id":"2","name":"Peqin","code":"PQ","status":"1"},{"zone_id":"59","country_id":"2","name":"Permet","code":"PR","status":"1"},{"zone_id":"60","country_id":"2","name":"Pogradec","code":"PG","status":"1"},{"zone_id":"61","country_id":"2","name":"Puke","code":"PU","status":"1"},{"zone_id":"64","country_id":"2","name":"Sarande","code":"SR","status":"1"},{"zone_id":"62","country_id":"2","name":"Shkoder","code":"SH","status":"1"},{"zone_id":"63","country_id":"2","name":"Skrapar","code":"SK","status":"1"},{"zone_id":"65","country_id":"2","name":"Tepelene","code":"TE","status":"1"},{"zone_id":"67","country_id":"2","name":"Tirane","code":"TR","status":"1"},{"zone_id":"66","country_id":"2","name":"Tropoje","code":"TP","status":"1"},{"zone_id":"68","country_id":"2","name":"Vlore","code":"VL","status":"1"}],"status":"1"}

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Sat Aug 22, 2020 2:58 am
by straightlight
What is on line 66 of that file?

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Sun Aug 23, 2020 3:51 am
by gerstavros
straightlight wrote:
Sat Aug 22, 2020 2:58 am
What is on line 66 of that file?
the code reading the address

Code: Select all

		if (isset($this->session->data['shipping_address'])) {
			$this->tax->setShippingAddress($this->session->data['shipping_address']['country_id'], $this->session->data['shipping_address']['zone_id']);
		} elseif ($this->config->get('config_tax_default') == 'shipping') {
			$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
		}
EDIT: it worked, file was somehow restored in default, or i never saved the changes...

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Sat Dec 12, 2020 6:59 pm
by debruyckerejohan
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Thu Apr 15, 2021 10:07 pm
by johans
debruyckerejohan wrote:
Sat Dec 12, 2020 6:59 pm
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan
THIS ONE WORKS!

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Thu Apr 15, 2021 10:10 pm
by straightlight
johans wrote:
Thu Apr 15, 2021 10:07 pm
debruyckerejohan wrote:
Sat Dec 12, 2020 6:59 pm
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan
THIS ONE WORKS!
Thanks for the feedback. However, this fix has already been integrated into the OC v3.0.3.7 release.

Re: trying to access array offset on value of type bool

Posted: Thu Apr 22, 2021 4:26 pm
by aerogel
straightlight wrote:
Sun Apr 26, 2020 6:05 am
See if the following could solved the issue for this version of PHP since it is still quite recent:

replace:

Code: Select all

if (isset($this->session->data['shipping_address'])) {
with:

Code: Select all

if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
life is such an easy journey when someone knows what to do!
thanks alot

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Fri Jun 18, 2021 1:05 am
by niczous
debruyckerejohan wrote:
Sat Dec 12, 2020 6:59 pm
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan
Hi!

I am using Version 3.0.3.6 and PHP 7.4

I tried to use the solution mentioned above but it doesn't work. This error affected the new registered customer. Previous customers are doing okay.

Thank you in advance.

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Fri Jun 18, 2021 1:43 am
by straightlight
niczous wrote:
Fri Jun 18, 2021 1:05 am
debruyckerejohan wrote:
Sat Dec 12, 2020 6:59 pm
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan
Hi!

I am using Version 3.0.3.6 and PHP 7.4

I tried to use the solution mentioned above but it doesn't work. This error affected the new registered customer. Previous customers are doing okay.

Thank you in advance.
Then, something else is affecting your store that may originate from an installed extension.

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Fri Jun 18, 2021 11:03 am
by niczous
straightlight wrote:
Fri Jun 18, 2021 1:43 am
niczous wrote:
Fri Jun 18, 2021 1:05 am
debruyckerejohan wrote:
Sat Dec 12, 2020 6:59 pm
thanks,
working with "Version 3.0.3.2"
it helped me to.
i changed in ../catalog/controller/startup/startup.php

if (isset($this->session->data['shipping_address'])) {
changes to
if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
AND
if (isset($this->session->data['payment_address'])) {
changes to
if (isset($this->session->data['payment_address']['country_id']) && isset($this->session->data['payment_address']['zone_id'])) {

Grz,
Johan
Hi!

I am using Version 3.0.3.6 and PHP 7.4

I tried to use the solution mentioned above but it doesn't work. This error affected the new registered customer. Previous customers are doing okay.

Thank you in advance.
Then, something else is affecting your store that may originate from an installed extension.
The last extension I installed was PHPmailer to solve my SMTP error on checkout and I have just uninstalled it but still getting the error on 166.

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Fri Jun 18, 2021 6:20 pm
by straightlight
niczous wrote:
Fri Jun 18, 2021 11:03 am
straightlight wrote:
Fri Jun 18, 2021 1:43 am
niczous wrote:
Fri Jun 18, 2021 1:05 am


Hi!

I am using Version 3.0.3.6 and PHP 7.4

I tried to use the solution mentioned above but it doesn't work. This error affected the new registered customer. Previous customers are doing okay.

Thank you in advance.
Then, something else is affecting your store that may originate from an installed extension.
The last extension I installed was PHPmailer to solve my SMTP error on checkout and I have just uninstalled it but still getting the error on 166.
Which full PHP version are you using? Also, are you sure your changes are reflecting? Which type of server package are you using? Are your PHP files being saved as UTF-8 without BOM? If you reduce your PHP version back to 7.3x releases, is the line 166 error still showing?

Re: [SOLVED] - trying to access array offset on value of type bool

Posted: Sat Jun 19, 2021 5:10 am
by niczous
straightlight wrote:
Fri Jun 18, 2021 6:20 pm
niczous wrote:
Fri Jun 18, 2021 11:03 am
straightlight wrote:
Fri Jun 18, 2021 1:43 am


Then, something else is affecting your store that may originate from an installed extension.
The last extension I installed was PHPmailer to solve my SMTP error on checkout and I have just uninstalled it but still getting the error on 166.
Which full PHP version are you using? Also, are you sure your changes are reflecting? Which type of server package are you using? Are your PHP files being saved as UTF-8 without BOM? If you reduce your PHP version back to 7.3x releases, is the line 166 error still showing?
Hi! Thank you so much for your response. I have deleted and re-uploaded all the files in the startup folder. Logout the site and create a new customer. Login using another computer to test. Finally, the error is solved. Thank you again.