What are some best practices for organizing and structuring PHP scripts to avoid issues with reusing them in a document?

When organizing and structuring PHP scripts to avoid issues with reusing them in a document, it is best practice to encapsulate related functions and classes in separate files and directories. This helps in maintaining a clean and organized codebase, making it easier to locate and reuse specific functionalities when needed.

// Example of organizing PHP scripts into separate files and directories

// File: functions.php
function calculateTotal($price, $quantity) {
    return $price * $quantity;
}

// File: classes/Product.php
class Product {
    private $name;
    private $price;

    public function __construct($name, $price) {
        $this->name = $name;
        $this->price = $price;
    }

    public function getName() {
        return $this->name;
    }

    public function getPrice() {
        return $this->price;
    }
}