Skip to content

Instantly share code, notes, and snippets.

@Div-Man
Forked from kamrankr/singleton.php
Created May 22, 2023 22:17
Show Gist options
  • Save Div-Man/9f710b9657873d6fbc2a06f537b4b7e8 to your computer and use it in GitHub Desktop.
Save Div-Man/9f710b9657873d6fbc2a06f537b4b7e8 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