[nycphp-talk] How to create a singleton class in PHP
Phil Powell
phillip.powell at adnet-sys.com
Thu Feb 12 16:05:20 EST 2004
Got it.. well, not the code working but I can copy and paste now (why I
couldn't before I have no idea).. see below for your code and its
results.. it's mixed. I do populate $GLOBALS['errorArray'], but only
once, in spite of $additionalErrorArray value which setErrorArray()
still thinks is NOT an array even though it is!
Phil
>>> and for the $GLOBALS kludge:
>>>
>>> class ActionHandler {
>>> function &getErrorArray () {
>>> return ActionHandler::setErrorArray ();
>>> }
>>>
>>> function &setErrorArray ($additionalErrorArray = NULL) {
>>> if ( !isset ($GLOBALS['errorArray']) ) {
>>> $GLOBALS['errorArray'] = array ();
>>> }
>>>
>>> if ( is_array ($additionalErrorArray) ) {
>>> $GLOBALS['errorArray'] += $additionalErrorArray;
>>> }
>>>
>>> return $GLOBALS['errorArray'];
>>> }
>>> }
>>>
>>> Both of those functions work 100% for anything I've thrown at them.
>>
>>
>> It works on mine as well. How it works is a mystery to me, how is it
>> working?
>>
>> Phil
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
function &setErrorArray($additionalErrorArray = '') { // "VOID" METHOD (THROWS AN ARRAY CAUGHT BY getErrorArray())
/*
static $errorArray = array();
if (is_array($additionalErrorArray)) $errorArray = $errorArray + $additionalErrorArray;
return $errorArray;
*/
print_r("additionalErrorArray = "); print_r($additionalErrorArray); print_r(" is array? "); print_r(sizeof($addtionalErrorArray)); print_r("<P>");
if (!isset($GLOBALS['errorArray'])) $GLOBALS['errorArray'] = array();
if (is_array($additionalErrorArray)) $GLOBALS['errorArray'] += $additionalErrorArray;
print_r("GLOBALS['errorArray'] = "); print_r($GLOBALS['errorArray']); print_r("<P>");
return $GLOBALS['errorArray'];
}
function &getErrorArray() {
return ActionHandler::setErrorArray();
}
OUTPUT
additionalErrorArray = Array ( ) is array? 0
GLOBALS['errorArray'] = Array ( )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/event/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/image/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/image_event_assoc/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/image_keyword_assoc/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/image_person_assoc/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/image_placement_assoc/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/keyword/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/person/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/person_event_assoc/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
additionalErrorArray = Array ( [willSelectFileArray] => Could not locate backup file /dev/placement/2004-01-01_FULL.sql ) is array? 0
GLOBALS['errorArray'] = Array ( [willSelectFileArray] => Could not locate backup file /dev/department/2004-01-01_FULL.sql )
--
Phil Powell
Web Developer
ADNET Systems, Inc.
11260 Roger Bacon Drive, Suite 403
Reston, VA 20190-5203
Phone: (703) 709-7218 x107 Cell: (571) 437-4430 FAX: (703) 709-7219
EMail: Phillip.Powell at adnet-sys.com AOL IM: SOA Dude
More information about the talk
mailing list