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.