What is the use of the instanceof keyword in PHP when working with Factory classes?

When working with Factory classes in PHP, the instanceof keyword can be used to check the type of an object created by the Factory. This can be helpful when you have multiple subclasses being created by the Factory and you need to perform different actions based on the specific subclass type.

// Example of using instanceof keyword with Factory classes
class VehicleFactory {
    public static function createVehicle($type) {
        if ($type == 'car') {
            return new Car();
        } elseif ($type == 'truck') {
            return new Truck();
        }
    }
}

$vehicle = VehicleFactory::createVehicle('car');

if ($vehicle instanceof Car) {
    echo "This is a Car object.";
} elseif ($vehicle instanceof Truck) {
    echo "This is a Truck object.";
}