How can global variables in PHP scripts impact performance and readability, and what alternatives can be considered?

Global variables in PHP scripts can impact performance by making it harder to track where variables are being modified or accessed. They can also make code less readable by introducing dependencies that are not explicitly declared. To improve performance and readability, consider using local variables within functions or classes instead of global variables. This will make your code more modular and easier to maintain.

// Using local variables instead of global variables
function calculateTotal($quantity, $price) {
    $total = $quantity * $price;
    return $total;
}

$quantity = 10;
$price = 5;
$total = calculateTotal($quantity, $price);
echo "Total: " . $total;