Repository navigation
Prevent array access notice when $update_info is null - #214
Merged
Merged
Conversation
schlessera
requested changes
Feb 24, 2020
| '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, |
Member
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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?
schlessera
approved these changes
Feb 24, 2020
$update_info is null
Member
|
Thanks for the PR, @dsifford ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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