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.