What are the best practices for handling invalid variable names like $4 in PHP when trying to manipulate strings?

When dealing with invalid variable names like $4 in PHP, the best practice is to use curly braces {} to enclose the variable name within double quotes when manipulating strings. This helps PHP to correctly interpret the variable name and prevent any syntax errors.

$invalidVar = '$4';
$fixedVar = "This is a string with the invalid variable: {$invalidVar}";
echo $fixedVar;