“Use of "self" in callables is deprecated” in WordPress: what it means and the fix
Short answer
It’s a deprecation notice from PHP 8.2 and later: a plugin or theme passes one of its own methods as a callback written as text, like 'self::format', to a PHP function such as array_map(). The code keeps working. PHP wants the class named explicitly: [self::class, 'format']. The same applies to parent:: and static::. Update the plugin, or send the message to its developer.
The message, exactly
A price-list plugin formats every price with one of its own methods, passed to array_map() as 'self::format'. PHP 8.1 runs it silently; PHP 8.2 adds the notice:
wp-content/plugins/price-list/price-list.php
<?php
class Price_List {
public static function format($price) {
return number_format($price, 2);
}
public static function all(array $prices) {
return array_map('self::format', $prices);
}
}
echo implode(', ', Price_List::all([5, 12.5])), "\n";
5.00, 12.50Deprecated: Use of "self" in callables is deprecated in /var/www/html/wp-content/plugins/price-list/price-list.php on line 8
5.00, 12.50php.net, in the PHP 8.2 deprecations: “Callables that are not accepted by the $callable() syntax (but are accepted by call_user_func()) are deprecated.” Among them "self::method", "parent::method", "static::method" and the array forms ["self", "method"] (php.net). Normal callbacks that name the class, "A::method" or ["A", "method"], are not affected.
Is it urgent?
No. The output is the same on PHP 8.1 and 8.2. It needs fixing at some point, because a future PHP version is expected to stop accepting these forms.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates).
- Already on the latest version? Send one full line of the message to its developer.
- Keep notices off your pages: the WordPress debug log shows how.
A check that reads code finds these while your site still runs PHP 8.1:
CompatNav reports them only where PHP really treats the text as a callback, so a text that merely looks like 'self::…' doesn’t raise a false alarm. The other PHP 8.2 changes: WordPress and PHP 8.2.
Key takeaways
- It’s a deprecation notice from PHP 8.2 and later; the code keeps working.
- It concerns callbacks written as text or arrays with
self,parentorstatic, such as'self::format'. - The fix names the class:
[self::class, 'format']. - Normal callbacks like
'My_Class::format'or[$this, 'format']are not affected. - A check that reads code finds these before you upgrade.
Frequently asked questions
Is it urgent?
No. The result is the same; PHP only adds the notice. A future PHP version is expected to stop accepting these callbacks, so the plugin should be fixed.
Does it affect add_action() and add_filter()?
WordPress calls hook callbacks from outside the class, where self never meant the plugin’s class, so such hooks already failed on older PHP versions. The notice on this page concerns callbacks a class passes to PHP functions from inside itself.
What about parent:: and static::?
The same notice and the same fix: [parent::class, 'method'] or [static::class, 'method'].
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.
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.