• Resolved joelworsham

    (@joelworsham)


    I’ve encountered this error:

    Catchable fatal error: Argument 1 passed to user_switching::filter_user_has_cap() must be of the type array, null given in /srv/www/realbigplugins/htdocs/wp-content/plugins/user-switching/user-switching.php on line 633

    This error was technically caused by me. I’m working on a plugin that modifies the $current_user object early on in the load. I actually made a mistake and caused the $current_user->all_caps property to be null. This will barely every happen I’m sure and isn’t super important, but perhaps a failsafe could be implemented to prevent a fatal error in this edge case. Your choice.

    https://www.ads-software.com/plugins/user-switching/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Hi Joel,

    As you’ve noted, the all_caps argument should be an array. It’s a mistake for it not to be, and a failsafe would not make any sense. Triggering a fatal error here is the correct behaviour because it alerts you to an error in your code.

    Anything that’s hooked into this filter expects an array. The reason User Switching triggers a fatal error is because it uses type hinting. Some other plugins may simply produce unexpected behaviour if they are expecting an array but receive null.

    There’s another thread about the same topic: https://www.ads-software.com/support/topic/fatal-error-on-filter_user_has_cap-call

    John

    Thread Starter joelworsham

    (@joelworsham)

    You preset a good point. Thank you for your quick response.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fatal Error’ is closed to new replies.