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']),
      ];
6
  • It's six lines, which line exactly? Also var_dump($billing_address) Commented Jun 26, 2020 at 15:57
  • the error appears on all the lines Commented Jun 26, 2020 at 16:17
  • place code about $billing_address[] so we can help you where is actual problem. Commented Jun 26, 2020 at 18:26
  • find a solution by if (isset($billing_address) { ... Commented Jun 27, 2020 at 12:18
  • 1
    Hello @Raph, welcome to stackoverflow. Please consult stackoverflow.com/help/how-to-ask. Commented Jul 15, 2020 at 12:39

1 Answer 1

-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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.