PHP Classes
elePHPant
Icontem

Singleton Class: Create, retrieve an delete instances of a class

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-07-22 (4 months ago) RSS 2.0 feedNot enough user ratingsTotal: 130 All time: 8,622 This week: 574Up
Version License PHP version Categories
singletonclass 1.0.1Custom (specified...7PHP 5, Language
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.

  Performance   Level  
Name: Mohamed Elbahja is available for providing paid consulting. Contact Mohamed Elbahja .
Classes: 9 packages by
Country: Morocco Morocco
Age: 22
All time rank: 11361 in Morocco Morocco
Week rank: 34 Up1 in Morocco Morocco Equal
Innovation award
Innovation award
Nominee: 3x

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
  Files folder image Files  
File Role Description
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Singleton.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:130
This week:0
All time:8,622
This week:574Up