-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid deprecation notice on PHP 8.1 due to converting false
to array
#1040
Conversation
…ray to avoid deprecation notices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM based on a visual review, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note about the starting state inside the condition.
Push back if I am misunderstanding.
@@ -832,12 +832,13 @@ public static function build_available_authorized_sites( $user_id = false, $cont | |||
$authorized_sites = get_transient( $cache_key ); | |||
|
|||
if ( $force || false === $authorized_sites ) { | |||
$sites = get_sites( | |||
$authorized_sites = ! is_array( $authorized_sites ) ? array() : $authorized_sites; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$authorized_sites = ! is_array( $authorized_sites ) ? array() : $authorized_sites; | |
$authorized_sites = array(); |
I think it should always start empty:
=== false
it's not an array$force === true
then we're repopulating the authorized sites from 0. If the old value is retained then each site will appear in the array twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point, I think this should always be a new empty array if we make it inside this conditional. I've made that change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Darin!
Description of the Change
In testing something else on Distributor, I was going PHP deprecation notices showing up on the internal Pull Content screen. This notice said:
PHP Deprecated: Automatic conversion of false to array is deprecated
. Looking at the code, we have a place where a value may befalse
and then later we use that as anarray
but we don't ever set that as anarray
first.This PR fixes that by adding a check to convert that variable to an
array
if it isn't already.How to test the Change
In an environment running PHP 8.1, go to the internal Pull screen and notice a PHP deprecation notice.
Check out the code in this PR and note the notice should no longer be there.
Ensure all connections show up properly in the Pull dropdown, that you can switch between connections successfully, and that you can pull in content.
Changelog Entry
Credits
Props @dkotter
Checklist: