What are common pitfalls when assigning URLs as strings in PHP and how can they be avoided?

Common pitfalls when assigning URLs as strings in PHP include forgetting to properly encode the URL, leading to potential security vulnerabilities or incorrect behavior when the URL contains special characters. To avoid this, it is recommended to use the `urlencode()` function to encode the URL before assigning it as a string in PHP.

$url = 'https://www.example.com/page?param=' . urlencode($param);