Singleton Example

<?php

class DatabaseConnection{


private $handle=null;

	private function __construct(){
	
		$this->handle="pp"; //create mysql connection here
		/*
                $this->handle=mysqi_connect('host','username','pass','dbname');
                 if(mysqli_connect_errno){
                echo "error in connecting to mysql". mysqli_connect_errno();
                exit();
                }
               */
	}
	
	public static function get(){
	static $db=null;
		if($db==null){
		echo "class object initialize single time";
		$db=new DatabaseConnection();
		}
		
		return $db;
	
	}
	
	public function gethandle(){

	return $this->handle;
	
	}

}

$dbobj=DatabaseConnection::get()->gethandle();
print_r($dbobj);
$dbobj=DatabaseConnection::get()->gethandle();
print_r($dbobj);

Output – class object initialize single timepppp