-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.php
More file actions
34 lines (23 loc) · 516 Bytes
/
example.php
File metadata and controls
34 lines (23 loc) · 516 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require "vendor/autoload.php";
class Example
{
use \ByJG\DesignPattern\Singleton;
protected $_uniqId;
protected function __construct()
{
$this->_uniqId = rand(0, 1000);
}
public function getId()
{
return $this->_uniqId;
}
}
// This works;
// Must return the same ID;
$example1 = Example::getInstance();
echo $example1->getId() . "\n";
$example2 = Example::getInstance();
echo $example2->getId() . "\n";
// That cannot work!
$example3 = new Example();