Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created November 22, 2017 06:34
Show Gist options
  • Select an option

  • Save lastday154/ecc68d3c0fbe3ba2166f26c4d40f5d6c to your computer and use it in GitHub Desktop.

Select an option

Save lastday154/ecc68d3c0fbe3ba2166f26c4d40f5d6c to your computer and use it in GitHub Desktop.
Singleton PHP
<?php
class UserFactory
{
private function __construct()
{
}
public static function Instance()
{
static $user = null;
if ($user === null) {
$user = new UserFactory();
}
return $user;
}
}
$fact = UserFactory::Instance();
$fact2 = UserFactory::Instance();
var_dump($fact== $fact2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment