0

In php 7.4 strict mode I have this error

PHP Notice: Trying to access array offset on value of type bool in I do not understand exactly the problem

Thank you

public array $billing;

the line where the error appear :

$this->billing = [
        'firstname' => $billing_address['entry_firstname'],            
        'state' => (!is_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name']),
        'zone_id' => $billing_address['entry_zone_id'],
        'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']),
      ];
Raph
  • 11
  • 1

1 Answers1

-1

The error means that you use a variable as array, but actually it is bool.

I guess that $billing_address is false instead of array.

It got false while you were trying to fetch if from DB or other source. So you should always check if you have a value there and put a default value like empty array []. Or throw an exception "billing address not found".

Maxim Demkin
  • 1,215
  • 11
  • 13