What are the potential pitfalls of using global variables in PHP?

Using global variables in PHP can lead to issues such as variable scope conflicts, making code harder to maintain and debug. To avoid these pitfalls, it's recommended to use local variables within functions and pass variables as parameters when needed.

// Avoid using global variables by passing variables as parameters to functions

$globalVar = 10;

function doSomething($var) {
    // Use local variables instead of global variables
    $result = $var * 2;
    return $result;
}

echo doSomething($globalVar); // Output: 20