“mktime() expects at least 1 argument, 0 given”: what it means after PHP 8, and the fix

By CompatNav · Published · Last reviewed · 3 min read

Short answer

It’s a fatal error from PHP 8.0 and later: a plugin or theme calls mktime() with nothing between the brackets to get the current time. PHP 7.4 still answered, with a deprecation notice (“You should be using the time() function instead”); PHP 8.0 requires at least one argument, and the page stops. The fix is to call time(), which gives exactly the same value. Switch PHP back if the site is down, then update the plugin or theme, or send the message to its developer.

The message, exactly

An event countdown gets the current time with mktime(). PHP 7.4 warns and answers; PHP 8.0 stops:

wp-content/plugins/event-countdown/countdown.php

<?php
$now = mktime();
$event = $now + 3600;
echo 'Starts in ', round(($event - $now) / 60), " minutes\n";

Output on PHP 7.4.33

Deprecated: mktime(): You should be using the time() function instead in /var/www/html/wp-content/plugins/event-countdown/countdown.php on line 2
Starts in 60 minutes

Output on PHP 8.0.30the script stopped

Fatal error: Uncaught ArgumentCountError: mktime() expects at least 1 argument, 0 given in /var/www/html/wp-content/plugins/event-countdown/countdown.php:2
Stack trace:
#0 /var/www/html/wp-content/plugins/event-countdown/countdown.php(2): mktime()
#1 {main}
  thrown in /var/www/html/wp-content/plugins/event-countdown/countdown.php on line 2

php.net, in the PHP 8.0 changes: “mktime() and gmmktime() now require at least one argument. time() can be used to get the current timestamp.” (php.net)

What it means

mktime() builds a timestamp from an hour, minute, second, month, day and year. Called with none of them, it used to fill in “now” for each, which made it a roundabout way to write time(). PHP 7.4 warned about that; PHP 8.0 turned the warning into an error. On a website, that’s WordPress’s critical error page.

Fix it, in order

  1. Site down? Switch PHP back in your hosting panel, or pause the plugin through the link in WordPress’s email: the critical error guide.
  2. Find the plugin or theme from the path in the message.
  3. Update it (Dashboard → Updates).
  4. Already on the latest version? Send the message to its developer: the fix is one word.

Found before you switch

The call is in the code, so a check that reads code finds it while your site still runs PHP 7.4:

The other PHP 8.0 changes that stop old code: moving from PHP 7.4 to PHP 8.

Key takeaways

  • PHP 7.4: “mktime(): You should be using the time() function instead”, and the code ran.
  • PHP 8.0 and later: “Uncaught ArgumentCountError: mktime() expects at least 1 argument, 0 given”.
  • mktime() without arguments meant “now”; time() returns the same timestamp.
  • gmmktime() changed the same way in PHP 8.0.
  • A check that reads code finds the call before you switch.

Frequently asked questions

Will replacing mktime() with time() change anything?

No. Both return the current Unix timestamp; in our test the countdown printed the same with time() on PHP 7.4 and 8.5. mktime() with arguments, building a date from hour, day and so on, is unaffected by this change.

Why did it work for years?

PHP accepted mktime() without arguments and filled in the current time; PHP 7.4 showed a deprecation notice for it, as our test shows. PHP 8.0 made the first argument, the hour, required.

Where is mktime() used in WordPress sites?

In the date code of plugins and themes, such as countdowns or event lists. WordPress 7.1.2’s own code never calls mktime() without arguments; the path in the message names the plugin or theme.

Check your own site before you upgrade

CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.

Get CompatNav on wordpress.org How it works

Sources

About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.