class Product { public function __construct($name, $price) { $this->name = $name; $this->price = $price; } } $product = Product::getInstance('Shirt', 20.00);
class Car { public static function getInstance() { return new Car(); } } $car = Car::getInstance();In this example, the getInstance method is declared as static. We can call this method on the Car class without instantiating an object of the class. The method returns a new instance of the Car class. Product getInstance is commonly used in many PHP packages and libraries that use object-oriented programming. Popular libraries that use this method include Laravel, Symfony, and CodeIgniter.