“Using ${var} in strings is deprecated” in WordPress: what it means and the fix

By CompatNav · Published · Last reviewed · 3 min read

Short answer

It’s a deprecation notice from PHP 8.2 and later: a plugin or theme puts a variable into text as "${name}", an old spelling PHP is phasing out. The code keeps working, and the message itself names the fix: {$name} instead of ${name}. A second wording, about ${expr} and variable variables, has a slightly different fix. Update the plugin, or send the message to its developer.

The message, exactly

A greeting plugin builds a sentence with the old spelling. On PHP 8.1 it runs silently; on PHP 8.2 the notice appears, and it names the fix:

wp-content/plugins/simple-greeting/simple-greeting.php

<?php
$name = 'Anna';
echo "Hello ${name}!\n";

Output on PHP 8.1.34

Hello Anna!

Output on PHP 8.2.34

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /var/www/html/wp-content/plugins/simple-greeting/simple-greeting.php on line 3
Hello Anna!

php.net: “The “${var}” and “${expr}” style of string interpolation is deprecated.” (php.net)

The second wording

When the code inside the braces is more than a plain name, for example a variable whose value is the name of another variable, PHP 8.2 uses a different message:

wp-content/plugins/simple-greeting/simple-greeting.php

<?php
$field = 'name';
$name  = 'Anna';
echo "Hello ${$field}!\n";

Output on PHP 8.1.34

Hello Anna!

Output on PHP 8.2.34

Deprecated: Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead in /var/www/html/wp-content/plugins/simple-greeting/simple-greeting.php on line 4
Hello Anna!

Same notice, same urgency; the replacement it names is {${expr}}. php.net: “Use “$var”/"{$var}" and “{${expr}}”, respectively.” (php.net)

Is it urgent?

No. In both examples the text is exactly the same on 8.1 and 8.2. It needs a fix at some point, because a future PHP version is expected to remove what is deprecated today, and because PHP reports it when the file loads: a plugin with many such lines adds many notices to your log.

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 the full message to its developer. It names the replacement, so the fix is quick.
  4. Keep notices off your pages meanwhile: the WordPress debug log shows how to log them instead.

A check that reads code finds every occurrence, while your site still runs PHP 8.1:

This is one of several PHP 8.2 notices; the others are in WordPress and PHP 8.2.

Key takeaways

  • It’s a deprecation notice from PHP 8.2 and later; the text comes out exactly as before.
  • Two wordings: “Using ${var} in strings is deprecated, use {$var} instead” and “Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead”.
  • The fix moves one character: ${name} becomes {$name} (or simply $name).
  • The notice appears when the file loads, so it shows even for text that is never displayed.
  • A check that reads code finds every occurrence before you upgrade.

Frequently asked questions

Is it dangerous?

No. The text is built exactly as before; PHP only adds the notice. A future PHP version is expected to drop the old spelling, so the plugin should be updated.

Why does phpMyAdmin or another tool show the same message?

Any PHP program written with the old spelling gets it on PHP 8.2 and later. The fix is the same: update that program.

Can I fix it in the plugin myself?

The change is small, but edits to a plugin’s files are lost with its next update. Update the plugin, or send the message to its developer.

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.