note 49698 added to language.variables.scope

From: Date: Sat, 05 Feb 2005 10:54:31 +0000
Subject: note 49698 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-84552@lists.php.net to get a copy of this message
<?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]; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49698 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49698&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49698&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49698&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49698&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49698&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49698&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84552) next »