What are the potential pitfalls of not properly formatting PHP variables in a link?

If PHP variables are not properly formatted in a link, it can lead to errors or unexpected behavior in the application. To avoid this, it is important to properly concatenate the variables within the link using the concatenation operator (.) or by enclosing the variables within curly braces {}.

// Incorrect way of formatting PHP variables in a link
$link = "example.com/page?var1=$var1&var2=$var2";

// Correct way of formatting PHP variables in a link
$link = "example.com/page?var1=" . $var1 . "&var2=" . $var2;
// or
$link = "example.com/page?var1={$var1}&var2={$var2}";