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 are the methods of array in java?
What are the new features in php 7?
What is meant by pear in php? What is the purpose of it?
Tell me how to get the value of current session id?
What is the use of @ in php?
What is the string concatenation operator in php?
Which function is used in php to delete a file?
How do I find out the number of parameters passed into function9?
Why do we use polymorphism in php?
What are sql injections, how do you prevent them and what are the best practices?
Why do we need session?
What are the advantages of oops in php?
What is parent __construct ();?
Does php require a web server?
Write a select query that will be displayed the duplicated site name and how many times it is duplicated?