28 arguments are required

Today, I saw a PHP error you don’t see everyday:

Fatal error: Uncaught ArgumentCountError: 28 arguments are required, 1 given in…

You heard it right. There was somewhere a function that needed 28 arguments. Well, not exactly that number. Fortunately, the PHP stack trace is kind enough to give you enough information to solve the arcane.

It seems like an innocent typo, right? A printf when an echo is enough and faster. No, it isn’t. The main problem here is that things have changed under the hood, and sometimes, small changes can lead to bad errors.

The printf function has changed in PHP 8.0.0.

As of PHP 8.0.0, a ArgumentCountError is thrown when less arguments are given than required. Prior to PHP 8.0.0, false was returned and a E_WARNING emitted instead.

So what happened here was that the user had 28 ‘%’ format specifiers in its text. Maybe a long URL-encoded string? Who knows.

I tried to remember the most extended function signature I encountered and then recalled the famous WideCharToMultiByte.

Not even near 28 arguments.

@online{zaerl2024-28-arguments-are-required,
  author = {Francesco Bigiarini},
  title = {28 arguments are required},
  date = {2024-04-24},
  url = {https://zaerl.com/2024/04/24/28-arguments-are-required/},
  urldate = {2024-04-24}
}