Skip to content

Instantly share code, notes, and snippets.

@kamrankr
Last active May 22, 2023 22:17
Show Gist options
  • Save kamrankr/91424e53c55554c52f3d to your computer and use it in GitHub Desktop.
Save kamrankr/91424e53c55554c52f3d to your computer and use it in GitHub Desktop.
Php Singleton example
<?php
class Mysingleton
{
private static $instance;
private function __construct()
{}
public static function getInstance()
{
if ( self::$instance == NULL )
{
self::$instance = new Mysingleton;
}
return self::$instance;
}
public function k()
{
echo 'Accessing Through Singleton';
}
}
#$k = Mysingleton::getInstance();
#$k->k();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment