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

Using global variables within functions can lead to issues such as variable scope conflicts, making the code harder to debug and maintain. To solve this issue, it is recommended to pass variables as parameters to functions or use the "global" keyword within the function to access global variables.

// Avoid using global variables within functions
$globalVar = 10;

function myFunction() {
    global $globalVar;
    echo $globalVar;
}

myFunction();