“Calling get_class() without arguments is deprecated” in WordPress (PHP 8.3)

By CompatNav · Published · Last reviewed · 2 min read

Short answer

It’s a deprecation notice from PHP 8.3 and later: a plugin or theme asks for the name of its own class with get_class() and no arguments. The code keeps working and gives the same result. PHP wants it written explicitly instead: self::class (or static::class) inside a class. Update the plugin, or send the message to its developer.

The message, exactly

An invoicing plugin writes which class created a document. PHP 8.2 runs it silently; PHP 8.3 adds the notice:

example.php

<?php
class Invoice {
    public function describe(): string {
        return 'Created by ' . get_class();
    }
}

echo (new Invoice())->describe(), "\n";

Output on PHP 8.2.34

Created by Invoice

Output on PHP 8.3.35

Deprecated: Calling get_class() without arguments is deprecated in /var/www/html/example.php on line 4
Created by Invoice

php.net, in the PHP 8.3 deprecations: “Calling get_class() and get_parent_class() without arguments is now deprecated.” (php.net)

Is it urgent?

No. The output is the same on PHP 8.2 and 8.3. It needs fixing at some point, because a future PHP version is expected to remove what is deprecated today.

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.

A check that reads code finds every call while your site still runs PHP 8.2:

The other PHP 8.3 changes are in WordPress and PHP 8.3.

Key takeaways

  • It’s a deprecation notice from PHP 8.3 and later; the result is the same as before.
  • get_parent_class() without arguments gets the same notice.
  • The fix inside a class is self::class (or static::class when child classes should report their own name).
  • A check that reads code finds every call before you upgrade.

Frequently asked questions

Is it dangerous?

No. The code works and returns the same class name; PHP only adds the notice. A future PHP version is expected to remove the call without arguments.

What’s the difference between self::class and static::class?

self::class is the class where the code is written; static::class is the class of the object it runs on, which can be a child class. get_class() without arguments behaved like self::class.

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.