From: Timo Tijhof Date: Thu, 19 Apr 2018 01:39:23 +0000 (+0100) Subject: API: Fix PHP Warning for "count(): Parameter must be an array" X-Git-Tag: 1.31.0-rc.0~25^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=fac144565411ba560c96b5913b2b054e48deadd7;p=lhc%2Fweb%2Fwiklou.git API: Fix PHP Warning for "count(): Parameter must be an array" Found by the new ApiUserrights test introduced in 5ab1bee6bcf: > includes/specials/SpecialUserrights.php:462 > includes/specials/SpecialUserrights.php:405 > includes/api/ApiUserrights.php:116 The $tags parameter of the UserrightsPage::doSaveUserGroups() method must be an array and is not nullable. Fix the caller to not pass null, but an empty array. Bug: T182377 Change-Id: Ic9be6a0bddfac023de765c810c07a64d651c33b4 --- diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 56c2c84cc8..47f3bc5a4d 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -100,7 +100,7 @@ class ApiUserrights extends ApiBase { $tags = $params['tags']; // Check if user can add tags - if ( !is_null( $tags ) ) { + if ( $tags !== null ) { $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $pUser ); if ( !$ableToTag->isOK() ) { $this->dieStatus( $ableToTag ); @@ -112,8 +112,9 @@ class ApiUserrights extends ApiBase { $r['user'] = $user->getName(); $r['userid'] = $user->getId(); list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups( + // Don't pass null to doSaveUserGroups() for array params, cast to empty array $user, (array)$add, (array)$params['remove'], - $params['reason'], $tags, $groupExpiries + $params['reason'], (array)$tags, $groupExpiries ); $result = $this->getResult();