devinsays/options-framework-plugin

Sanitization for multicheck + PHP 7.2

bryan-farris opened this issue · 3 comments

Looks like there's an issue with the of_sanitize_multicheck function when running PHP 7.2.

Here's what it looks like when options get saved and a multicheck is one of the fields: https://cl.ly/1Y0o3R1h042v

It looks like this is the part of the function that is causing the issue:

foreach( $option['options'] as $key => $value ) {
    $output[$key] = false;
}

Going to continue to troubleshoot.

Just following up here. Looks like this is related to how PHP 7.1+ handles variables that aren't set or initialized as an array. If I change $output = ''; to $output = array(); this seems to resolve the issue.

This also solves the issue reported in #229 as far as I can tell.

One last follow-up. This is due to $output not being set or initialized as an array. Previous versions of PHP apparently handled this without issue but 7.1+ requires that the array be defined explicity.

You can read more here: https://tehnoblog.org/php-7-1-warnings-illegal-string-offset-cannot-assign-empty-string-to-string-offset-working-fine-in-php-7-0-and-lower/

That said, I'm going to open a pull request for this change, seems to be a pretty easy one.

Disregard. The latest version of the plugin here on GitHub already has this change. Should've checked there first: https://github.com/devinsays/options-framework-plugin/blob/master/includes/class-options-sanitization.php#L79