What are the potential performance implications of using a separate function for database connection initialization in PHP applications?

Using a separate function for database connection initialization in PHP applications can potentially improve code readability and maintainability. However, it may also introduce a slight performance overhead due to the additional function call. To mitigate this, consider using a singleton pattern to ensure that only one instance of the database connection is created and reused throughout the application.

class Database {
    private static $instance = null;
    private $connection;

    private function __construct() {
        $this->connection = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
    }

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

    public function getConnection() {
        return $this->connection;
    }
}

// Example of using the Database class
$db = Database::getInstance();
$connection = $db->getConnection();