Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2017-07-22 (1 year ago)  | | Not enough user ratings | | Total: 136 | | All time: 8,722 This week: 376 |
|
Description | | Author |
This class can create, retrieve an delete instances of a class.
It can create a unique instance of a given class, so next time an instance of the class is requested, it will return the same instance.
The class can also discard the instance of a class that was previously created. | |
 |
|
Innovation award
 Nominee: 4x |
|
Details
Singleton
get objects instances by singleton class
Examples
Get Instances
require_once('path/to/Singleton.php');
class Test extends Singleton
{
public $test;
// code
}
$test1 = Test::getInstance();
$test1->test = 'test';
function testGetInstance() {
$test = Test::getInstance();
echo PHP_EOL;
var_dump($test->test);
}
testGetInstance();
// output:
// string(4) "test"
Get Instances By Reference
require_once('path/to/Singleton.php');
class Test extends Singleton
{
public $test;
}
$test = &Test::getInstance();
$test->test = 'test';
function testCallback() {
$test = &Test::getInstance();
$test = null;
}
echo PHP_EOL;
var_dump($test);
testCallback();
echo PHP_EOL;
var_dump($test);
// output:
// object(Test)#1 (1) {
// ["test"]=>
// string(4) "test"
// }
//
// NULL
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.