What are the potential pitfalls of including a PHP script in another file and how can these issues be resolved?

Potential pitfalls of including a PHP script in another file include variable scope conflicts, function redeclaration errors, and potential security vulnerabilities if the included file is not properly sanitized. To resolve these issues, you can use PHP's include_once or require_once functions to ensure that the script is only included once, and encapsulate the included code within a function to prevent variable and function name conflicts.

// Include the file using require_once to avoid redeclaration errors
require_once 'included_script.php';

// Encapsulate the included code within a function to prevent scope conflicts
function includedFunction() {
    // Code from included_script.php
}

// Call the function to execute the included code
includedFunction();