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
Explain the difference between $message and $$message?
Can php replace javascript?
What is difference between php and wordpress?
What is orm in php framework?
What is the difference between null and empty?
i m a B.E,passed out few yrs bak failed to find good job due to less marks now thinkin of a career as PHP developer. is it a lucarative field and wat r career prospects; hv heard dat initial salary is very less bout 6k also most jobs r contrct jobs.pls guide me need ur valuable advice.pls hellppp!! thnx..
So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
What types of MYSQL function available for affecting columns
Is php deprecated?
Is php dying 2018?
What is self in php?
What is isset php?
What are php filters?
Suppose we receive a form submitted by a post to subscribe to a newsletter. This form has only one field, an input text field named email. How would we validate whether the field is empty? Print a message "the email cannot be empty" in this case?
What is design pattern? Explain all including singleton pattern?