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 how we can retrieve the data in the result set of mysql using php?
what the new feature add in php 7.2?
What does the arrow mean in php?
Which php function will attach one file to another?
Name and explain five of the PHP error constants?
How to redirect https to http url and vice versa in .htaccess?
Tell me are parent constructors called implicitly inside a class constructor?
Tell me in php, objects are they passed by value or by reference?
What is print_r?
How check field is empty or not in php?
What is the use of htmlspecialchars in php?
What is the use of stripslashes in php?
What is a lambda function in php?
What is a http session?
What are the features of php?