Design a class that should always return a single object ?
Answer Posted / amitverma
class DB {
private static $_singleton;
private $_connection;
private function __construct(){
$this->_connection = mysql_connect();
}
public static function getInstance(){
if (is_null (self::$_singleton)) {
self::$_singleton = new DB();
}
return self::$_singleton;
}
}
$db = DB::getInstance();
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
how to track no of users logged in?
Which function will suitably replace 'x' if the size of a file needs to be checked? $Size=x(filename);
Explain me what is the meaning of a persistent cookie?
Which is better wamp or xampp?
What is "print" in php?
How php statement is different from php script?
How can you create a session in php?
What library is used for pdf in php?
Define anonymous classes in php7?
What is the best way to change the key without changing the value of a php array element?
Why delimiter is used in mysql?
Which function is used to read a single character from a file in PHP.
What is an abstract class in php?
Is laravel better than codeigniter?
Is time a dependent variable?