Support

Account

Home Forums ACF PRO PHP 8 – Trying to access array offset on value of type bool

Solving

PHP 8 – Trying to access array offset on value of type bool

  • I’m updating to PHP 8 from 7.4 and getting the above error when I’m getting an image array

    $section_background_image = get_field('section_background_image');
    $small = $section_background_image['sizes']['medium'];

    This works fine in PHP7.4 but not in 8

  • You need to test the value before you use it. Fields with no values return null or false depending on the field type.

    
    $section_background_image = get_field('section_background_image');
    if ($section_background_image) {
      // do something with the array
    }
    
  • Hi thanks for the fast reply

  • PHP 8 is overall much more strict when if comes to validation of variables before using them. PHP 8 will issue an error for many things that are either ignored or cause a warning in PHP 7.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.