Fatal error: Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, bool given

313 views Asked by At

I have used such a code to display the captcha error on the login page that I have designed (this code is located in the functions.php file):

$error_codes =  join( ',' , $user->get_error_codes() );

$error_codes ->add( 'error_captcha', 'error_captcha' );
     return $error_codes;

But it keeps showing me the following error and I don't know what to do:

Fatal error: Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, bool given
1

There are 1 answers

6
Justinas On BEST ANSWER
  1. Make sure your $user->get_error_codes() returns array or null: implode(',' , $user->get_error_codes() ?: []);
  2. $errorcodes->add will throw error, because implode (join is alias) returns string. And string does not have any methods. Don't know what you want to do here