Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7.4 Notice: Trying to access array offset on value of type null in inc/acf.php #543

Closed
richaber opened this issue Aug 10, 2020 · 0 comments · Fixed by #544
Closed

PHP 7.4 Notice: Trying to access array offset on value of type null in inc/acf.php #543

richaber opened this issue Aug 10, 2020 · 0 comments · Fixed by #544
Assignees

Comments

@richaber
Copy link
Contributor

inc/acf.php makes some assumptions about arrays being present, when they might not actually exist (and are null).

On PHP 7.4, this throws notices like the following:

Notice: Trying to access array offset on value of type null in inc/acf.php on line 24
Notice: Trying to access array offset on value of type null in inc/acf.php on line 53

On Line 24, this can trigger if get_sub_field( 'background_options' ) doesn't return a value, and the ternary tries falling back to get_field( 'background_options' )['background_options']; (where the ['background_options'] array key might be null because get_field did not return an array):

$background_options = get_sub_field( 'background_options' ) ? get_sub_field( 'background_options' ) : get_field( 'background_options' )['background_options'];

Similarly, on Line 53, an assumption is made that we actually have a $background_options['background_type']['value'], which might also be null:

'background_type' => $background_options['background_type']['value'],

In tracing the execution, I can see a lot of null values due to arrays not being present where they were assumed to be, or null array keys...

24: get_sub_field( 'background_options' ) = false
24: get_field( 'background_options' ) = NULL
24: get_field( 'background_options' )['background_options'] = NULL
53: $background_options['background_type']['value'] = NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants