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
What is active record in php?
What is form action php?
Is apache needed for php?
What does the function get_magic_quotes_gpc() means?
What is namespace and use in php?
How many types of array are there in php?
Explain php parameterized functions.
What are objects in php?
How to join multiple strings stored in an array into a single string?
Tell me how to execute an sql query? How to fetch its result?
Why do we use inheritance in php?
Explain about a search-friendly site looks like?
Tell us what does $_cookie means?
What is difference between mysql_fetch_array and mysql_fetch_assoc?
What is repository in php?