What are some best practices for organizing PHP scripts to avoid errors related to function calls and includes?

To avoid errors related to function calls and includes in PHP scripts, it's best practice to organize your code by creating separate files for functions and including them where needed. This helps to ensure that functions are defined before they are called and reduces the chances of including the same file multiple times. Additionally, using namespaces can help prevent naming conflicts.

// functions.php
function myFunction() {
    // function code here
}

// index.php
include 'functions.php';
myFunction();