Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 31 lines (20 sloc) 0.622 kB
a23984f @chriso First commit
authored
1 <?php
2
3 trait Singleton {
4
5 protected function __construct() {
6 //Not allowed.
7 }
8
9 protected function __clone() {
44e086e @chriso Added another trait
authored
10 //Not allowed.
a23984f @chriso First commit
authored
11 }
12
13 public static function getInstance(/* $arg1, $arg2, $argN */) {
14 static $instance;
15
16 if (null === $instance) {
17 $class = new ReflectionClass(__CLASS__);
18
19 $instance = $class->newInstanceWithoutConstructor();
20
21 $constructor = $class->getConstructor();
22 $constructor->setAccessible(true);
23 $constructor->invokeArgs($instance, func_get_args());
24 }
25
26 return $instance;
27 }
28
29 }
30
Something went wrong with that request. Please try again.