Support

Account

Home Forums Bug Reports Trying to access offset value of type bool

Solving

Trying to access offset value of type bool

  • Hello, I am having the following issues, which I found in my debug.log.

    [25-Sep-2020 18:28:15 UTC] PHP Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/u443551283/domains/cuak.online/public_html/wp-config.php on line 75
    [25-Sep-2020 18:28:15 UTC] PHP Notice: Trying to access array offset on value of type bool in /home/u443551283/domains/cuak.online/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-field-group-functions.php on line 58
    [25-Sep-2020 18:28:15 UTC] PHP Notice: Trying to access array offset on value of type bool in /home/u443551283/domains/cuak.online/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-field-group-functions.php on line 59
    [25-Sep-2020 18:28:15 UTC] PHP Notice: Trying to access array offset on value of type bool in /home/u443551283/domains/cuak.online/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-field-group-functions.php on line 59

    I do not know how to solve them. Here is the code that supposedly is conflicting:

    // Store field group using aliasses to also find via key, ID and name.
    $store->set( $field_group[‘key’], $field_group );
    $store->alias( $field_group[‘key’], $field_group[‘ID’] );

    What should I do? The error is connected to the submission of a Frontend Form coming from the ACF Frontend plugin.

    Kind Regards, Tomas.

  • I can confirm that 5.9.1… and, after an upgrade to 5.9.3, I’m getting a similar error.

    Code is pretty simple:

    // all other meta
    	if ( ! empty( $value ) ) {
    		update_field( $wp_postmeta, $value, $post_id );
    	} else {
    		delete_field( $wp_postmeta, $post_id );
    	}

    Errors reported:
    PHP Notice: Trying to access array offset on value of type bool in [local install]/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php on line 279

    The field ( $wp_postmeta ) exists and has an ACF field key.

    Not sure where to go from here except converting it to delete_post_meta();.

  • Apologies… somehow my comment posted twice.

  • Is this happening on the update_field() call or the delete_field() call.

    Either way… when you call these function using the field name ACF attempts to figure out what the field key is. If no value is currently stored for the field for the specific post ID then ACF fails to find the correct field key reference.

    When calling any ACF function like update_field() where is it possible that a value does not already exist in the database then you must use the field key when calling this function and not the field name.

    Granted, this is probably something in ACF that is causing the error, probably not checking that $field is an array before doing something else. However, even if this was correctly checked and the error was removed the update_field() call would still fail where there is not already a value for the field in the database.

  • Thanks, John.
    In my case, the error is only on the delete_field();

  • My guess is that it is due to trying to delete a field that does not have an existing value in the DB.

  • I don’t necessarily expect it to exist.
    That might be a misunderstanding on my part.
    I assumed it worked like delete_post_meta().
    …”Delete if it’s there. Move along if not.”

  • One of ACF’s function is returning false when looking by field name. What you’re going to need to do is check to see if the field has a value before attempting to delete it.

    
    
    function delete_field( $selector, $post_id = false ) {
    	
    	// filter post_id
    	$post_id = acf_get_valid_post_id( $post_id );
    	
    	
    	// get field
    	$field = acf_maybe_get_field( $selector, $post_id );
    	
    	
    	// delete
    	return acf_delete_value( $post_id, $field );
    	
    }
    

    acf_maybe_get_field() is returning false
    acf_delete_value() expects $field to be an array, which it is not.

    The last line of this function should likely be

    
    if ($field) {
      return acf_delete_value( $post_id, $field );
    }
    

    of the function acf_delete_value() should be checking to see if $field has a value before attempting to use it.

    I would call this a bug. You should submit it here https://www.advancedcustomfields.com/contact/

    In the mean time, as a fix, you can either use the field key when calling these or check for a value.

    I would use the field key because as I already mentioned update_field() using the field name where the field does not already have a value will fail to save a value. This is covered in the documentation for this function https://www.advancedcustomfields.com/resources/update_field/

  • Thank you, John.
    All your information and solutions are very helpful.
    Much appreciated!

  • I’m late to the party, but just noticed this as well in my code.

    Has anyone reported it as a bug ? If so, what is the status ?

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

You must be logged in to reply to this topic.