What are the best practices for handling variables and parameters in PHP scripts?

When handling variables and parameters in PHP scripts, it is important to sanitize user input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. Additionally, using proper naming conventions and ensuring variables are properly scoped can improve code readability and maintainability.

// Example of sanitizing user input using filter_var()
$user_input = $_POST['user_input'];
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Example of using proper naming conventions and variable scope
function calculate_area($length, $width) {
    $area = $length * $width;
    return $area;
}