What are the differences between including a function in a separate file and creating a class for it in PHP?

When including a function in a separate file, the function can be reused across multiple scripts by simply including the file where the function is defined. On the other hand, creating a class for a function allows for better organization and encapsulation of related functionality, making it easier to manage and maintain code. Classes also enable the use of inheritance and polymorphism, providing more flexibility and extensibility in the code.

// Including a function in a separate file
// function.php
<?php
function myFunction() {
    // Function logic here
}

// script.php
<?php
include 'function.php';
myFunction();

// Creating a class for a function
class MyClass {
    public function myFunction() {
        // Function logic here
    }
}

// script.php
<?php
$myClass = new MyClass();
$myClass->myFunction();