“Automatic conversion of false to array is deprecated” in WordPress: what it means

By CompatNav · Published · Last reviewed · 3 min read

Short answer

It’s a deprecation notice from PHP 8.1 and later: a plugin or theme adds an entry to something that is false instead of a list. In WordPress this usually happens with a setting that doesn’t exist yet, because get_option() returns false for it. PHP still turns false into a list and the code keeps working. It depends on what is saved, so only your error log shows it. Update the plugin, or send the message to its developer.

The message, exactly

A visit-counter plugin reads its saved counts, finds nothing (false) and adds the first entry. PHP 8.0 does it silently; PHP 8.1 and later add the notice:

wp-content/plugins/visit-counter/visit-counter.php

<?php
function get_saved_counts() {
    return false; // like get_option() when the option doesn't exist yet
}

$counts = get_saved_counts();
$counts['home'] = 1;
echo $counts['home'], "\n";

Output on PHP 8.0.30

1

Output on PHP 8.1.34

Deprecated: Automatic conversion of false to array is deprecated in /var/www/html/wp-content/plugins/visit-counter/visit-counter.php on line 7
1

php.net calls this autovivification: “Autovivification is the process of creating a new array when appending to a value. Autovivification is prohibited from scalar values, false however was an exception. This is now deprecated.” (php.net)

Why WordPress code meets it so often

WordPress settings (options) are read with get_option(). For a setting that doesn’t exist yet, it returns false unless the code gives a default. The documentation, on the default value: “Default value to return if the option does not exist.” (developer.wordpress.org) So a plugin that reads its counts, its cache or its list of items on a fresh site gets false, then adds to it, and PHP 8.1 notices.

null is treated differently: php.net notes that “Autovivification from null and undefined values is still allowed” (php.net), and no notice appears, on PHP 8.1 or 8.5:

wp-content/plugins/visit-counter/visit-counter.php

<?php
$counts = null;
$counts['home'] = 1;
echo $counts['home'], "\n";

Output on PHP 8.1.34

1

Output on PHP 8.5.11

1

Is it urgent?

No. The result is the same on PHP 8.0 and 8.1. It needs a fix at some point, because a future PHP version is expected to stop converting false, and the notice can repeat on every page view.

Who fixes it

  1. Find the plugin or theme: the folder after wp-content/plugins/ or wp-content/themes/ in the message.
  2. Update it (Dashboard → Updates).
  3. Already on the latest version? Send one full line of the message to its developer.
  4. Keep notices off your pages: the WordPress debug log shows how to log them instead.

Why no check finds it beforehand

$counts['home'] = 1 is fine when $counts is a list, and only notices when it is false, which depends on what is saved on your site. A check that reads code can’t know that; CompatNav doesn’t report it, and its scan of the examples on this page finds nothing. This is one of several PHP 8.1 changes; the others are in WordPress and PHP 8.1.

Key takeaways

  • It’s a deprecation notice from PHP 8.1 and later; the code keeps working.
  • It happens when code adds an entry to a value that is false, typically a WordPress setting that was never saved.
  • The same with null is still allowed, without a notice.
  • It depends on values, so a check that reads code can’t find it: your error log does.
  • The fix for developers: start from an empty list when the value isn’t one, or pass a default to get_option().

Frequently asked questions

Is it urgent?

No. The result is the same as on PHP 8.0; PHP only adds the notice. A future PHP version is expected to stop converting false, so the plugin should be fixed.

Why does it stop after I save the plugin’s settings?

Saving creates the setting, so the plugin then reads a list instead of false. The notice comes back on a site where the setting doesn’t exist yet, so tell the developer anyway.

Why does WordPress return false?

get_option() returns false when an option doesn’t exist and no default was given. That is WordPress’s way of saying “not saved yet”.

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.