Last active
May 22, 2023 22:17
-
-
Save kamrankr/91424e53c55554c52f3d to your computer and use it in GitHub Desktop.
Php Singleton example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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