Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: Explain the Singleton design pattern in PHP.
Answer: The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It involves a private constructor and a static method to get the instance.

Example:

class Singleton { 
private static $instance; 
private function __construct() { /* private constructor */ } public static function getInstance() { 
if (!self::$instance) { 
self::$instance = new self(); 

return self::$instance; 

}
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook