What are some common pitfalls when implementing design patterns in PHP?

One common pitfall when implementing design patterns in PHP is not fully understanding the pattern before applying it, leading to incorrect or inefficient implementations. To avoid this, make sure to thoroughly study the design pattern and its intended use cases before incorporating it into your code.

// Incorrect implementation of a Singleton pattern
class Singleton {
    private static $instance;

    private function __construct() {}

    public static function getInstance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}

// Correct implementation of a Singleton pattern
class Singleton {
    private static $instance;

    private function __construct() {}

    public static function getInstance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    private function __clone() {}
    private function __wakeup() {}
}