The ${var} String Interpolation is Deprecated in PHP 8.2

The ${var} String Interpolation is Deprecated in PHP 8.2

PHP provides several ways to embed variables into string. Since PHP 8.2, string interpolation when the dollar sign is placed outside the curly braces ${var} is deprecated.

Since PHP 8.2, the following example will emit a deprecation warning:

<?php

$date = 8;
echo "${date}th December";

Example output:

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in main.php on line 4
8th December

The example can be rewritten using string interpolation when the dollar sign is placed inside the curly braces {$var}.

<?php

$date = 8;
echo "{$date}th December";

Leave a Comment

Cancel reply

Your email address will not be published.