note 49698 deleted from language.variables.scope by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:39:52 +0000 |
| Subject: | note 49698 deleted from language.variables.scope by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155571@lists.php.net to get a copy of this message | ||
Note Submitter: S dot Radovanovic at trimm dot nl
----
<?php
function __constructor($configfile = '', $blnSingleton = true) {
//We must define a static array that contains our reference(s) to the object(s)
static $arrSingletonObject = array();
//We also need to specify a static local member, that keeps track of the last
//initialize configfile, so that we can use this if no file has been specified
//(this way we enable it for the initializor, to work with a previously initialized
//config object, without knowing what configfile it uses
static $lastConfigfile;
if(!empty($configfile)) {
//Store the set configfile name in the static local member
$lastConfigfile = $configfile;
} else if(!empty($lastConfigfile)) {
//If the configfile was empty, we retrieve it from the last known initialized
$configfile = $lastConfigfile;
} else {
//if we've reached so far, it means no configfile has been set at all (now
//or previously), so we cannot continue
trigger_error("No configfile has been specified.", ERROR);
//Return (instead of an exit (or die)) so that the constructor isn't continued
return;
}
//Set the configuration file
$this->_configfile = $configfile;
//Only if we want to use singleton we may proceed
if($blnSingleton) {
//We must now check to see if we already have a reference to the (to be created) config
//object
if(!isset($arrSingletonObject[$this->_configfile])) {
//Create of reference of myself, so that it can be added to the singleton object array
$arrSingletonObject[$this->_configfile] = &$this;
//We can now proceed and read the contents of the specified ini file
$this->_parseIniFile();
} else {
//Associate myself with the reference of the existing config object
$this = $arrSingletonObject[$this->_configfile];
}
}
}
?>