What are the differences between calling a method in a PHP class as an instance method versus a static method?

When calling a method in a PHP class as an instance method, you need to create an object of the class and then call the method on that object. This allows the method to access instance variables and properties of the object. On the other hand, when calling a method as a static method, you can call the method directly on the class itself without needing to create an object. Static methods are useful for utility functions that do not require access to instance variables.

// Instance method
class MyClass {
    public function instanceMethod() {
        echo "This is an instance method";
    }
}

$obj = new MyClass();
$obj->instanceMethod();

// Static method
class MyClass {
    public static function staticMethod() {
        echo "This is a static method";
    }
}

MyClass::staticMethod();