Skip to content

Prevent array access notice when $update_info is null - #214

Merged
schlessera merged 2 commits into
wp-cli:masterfrom
dsifford:fix/php7.4-compat
Feb 24, 2020
Merged

schlessera merged 2 commits into
wp-cli:masterfrom
dsifford:fix/php7.4-compat

Conversation

@dsifford

Copy link
Copy Markdown
Contributor

This PR fixes a warning that shows up in PHP 7.4 when the command attempts to access an array index on NULL.

See https://wordpress.slack.com/archives/C02RP4T41/p1582500876002400 for more context.

closes #209
closes #213

Ping @schlessera

@dsifford
dsifford requested a review from a team as a code owner February 24, 2020 00:48
Comment thread src/Plugin_Command.php Outdated
'update' => (bool) $update_info,
'update_version' => $update_info['new_version'],
'update_package' => $update_info['package'],
'update_version' => is_array( $update_info ) ? $update_info['new_version'] : null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're dealing with WordPress, we should take the safest route possible to make it as robust as possible.

Therefore, it's preferable to use isset( $update_info['new_version'] ) instead of is_array( $update_info ), as it will also cover the case where $update_info is an array but does not contain the key new_version.

All checks should be updated to that effect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you'd want the call to isset to be chained after a call to is_array? Otherwise, wouldn't this still trigger the warning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^disregard

@schlessera schlessera added command:plugin-update Related to 'plugin update' command command:theme-update Related to 'theme update' command labels Feb 24, 2020
@schlessera schlessera added this to the 2.0.8 milestone Feb 24, 2020
@schlessera schlessera changed the title fix: guard against possible array access on null Prevent array access notice when $update_info is null Feb 24, 2020
@schlessera
schlessera merged commit 3f55805 into wp-cli:master Feb 24, 2020
@schlessera

Copy link
Copy Markdown
Member

Thanks for the PR, @dsifford !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:plugin-update Related to 'plugin update' command command:theme-update Related to 'theme update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trying to access array offset on value of type null get_item_list has an array access issue

2 participants