Support

Account

Home Forums Bug Reports Fatal error in update_field in repeater.php

Solving

Fatal error in update_field in repeater.php

  • Hello!

    I’ll try to be as extensive as I can about this..

    I’m using update_field to set an empty repeater field and get the following fatal error using PHP version 5.3.10:

    PHP Fatal error: Cannot unset string offsets in /path/to/wordpress/wp-content/plugins/advanced-custom-fields-pro/pro/fields/repeater.php on line 638

    Inside the update_field function on row 633 in /path/to/wordpress/wp-content/plugins/advanced-custom-fields-pro/pro/fields/repeater.php $value is 0 and of type string and the if-statement on row 638 erroneously evaluates to true and causes the fatal error when trying to unset inside the if-statement.

    I temporarily fixed this by extending the if-statement to also check if $value is an array:

    if( is_array($value) && isset($value['acfcloneindex']) ) {
        unset($value['acfcloneindex']);
    }

    The confirmed case is when using PHP 5.3.10 with ACF 5.1.0 and 5.1.3. It’s possible that this occurs in other places than in the repeater-code as well.

    My local machine:
    PHP 5.5.14
    Test string offset of string:

    php -a
    php > $var = 'test'; var_dump(isset($var['offset']));
    bool(false)

    Server:
    PHP 5.3.10
    Test string offset of string:

    php -a
    php > $var = 'test'; var_dump(isset($var['offset']));
    bool(true)

    I checked PHP’s changelog between these versions and isset is mentioned as changed and obviously works as expected in later versions of php.

  • Hello,
    I have the same error, with a simple text field !
    if I // update_field(‘slug_de_larticle’,$cSlug); then it works.
    BTW i use also a repeater field, but the text field is not a part of it.
    Thanks for your help.

  • 5 minutes later:

    If i use update_sub_field instead, it seems to work !

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

The topic ‘Fatal error in update_field in repeater.php’ is closed to new replies.