The PHP codebase I'm working on has an utility class that returns a database connection. The implementation looks like this:
class Database { private static $conn; private static $init = false; public static function connect() { if (!self::$init) { $cnf = new Configuration(); self::$conn = new DatabaseConnection($cnf->get('dbname'), $cnf->get('username'), $cnf->get('password')); self::$init = true; } return self::$conn; } } Things have been done this way to apparently spend lesser time on opening connections, which occur over a network.
Is instantiating a single database connection like this and returning that instance to all callers a good software engineering practice?