DownloadSingleton
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
|