Why is variable declaration not required in PHP and what potential pitfalls can arise from this?

In PHP, variable declaration is not required because PHP is a loosely typed language, meaning variables are automatically created when they are first used. However, this can lead to potential pitfalls such as accidentally mistyping a variable name and creating a new variable instead of using an existing one. To avoid this, it is recommended to always declare variables before using them to ensure clarity and prevent unexpected behavior.

<?php

// Declare variables before using them
$variable1 = 10;
$variable2 = "Hello";

// Using the declared variables
echo $variable1 . " " . $variable2;

?>