Jump to content

sprintf ArgumentCountError when using PHP 8.1


panormitis

Recommended Posts

On older php versions this would have generated just a warning, but now throws a fatal error.

Uncaught Exception ArgumentCountError: "3 arguments are required, 2 given" at ...vendors/minphp/language/src/Language.php line 125 {"exception":"[object] (ArgumentCountError(code: 0): 3 arguments are required, 2 given at ...vendors/minphp/language/src/Language.php:125)"} 

 

I tried a try-catch to suppress it but didn't help. Any ideas?

Link to comment
Share on other sites

I found a temporary workaround, initially I was trying a try-catch like this:

	//            $output = call_user_func_array('sprintf', $args);
              try { $output = call_user_func_array('sprintf', $args); }
              catch(ArgumentCountError $e) { }
	

However it didn't work. But this did:

	//            $output = call_user_func_array('sprintf', $args);
              try { $output = sprintf($args[0], $args[1], $args[2]); }
              catch(ArgumentCountError $e) { }
	

 

EDIT: Ok the following works too, just needed a backslash ?

	//            $output = call_user_func_array('sprintf', $args);
              try { $output = call_user_func_array('sprintf', $args); }
              catch(\ArgumentCountError $e) { }
	
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...