PHP 8 compatibility: TypeError: count(): Argument #1 ($value) must be of type Countable at adding a new rule

Created on 23 May 2023, over 1 year ago

Since PHP8 count() will now throw TypeError on invalid countable types passed to the value parameter. As $options[3] is an empty String while adding a new rule in $form['shib_auth_roles'] an error is thrown each time a new rule is ought to be added.

TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in shib_auth_edit_form() ...).

Solution: Simply check if $options[3] is not an empty String before trying to count it:

'#default_value' => ($options[3] !== "") && (count($options[3]) > 1 || (count($options[3]) == 1 && $options[3] != "")) ? $options[3] : array(),

See attached patch

🐛 Bug report
Status

Needs review

Version

4.5

Component

Code

Created by

🇩🇪Germany meyerrob

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024