NYCPHP Meetup

NYPHP.org

[nycphp-talk] How to create a singleton class in PHP

Dan Cech dcech at phpwerx.net
Thu Feb 12 16:15:47 EST 2004


You have a typo in the sizeof call.

In addition, the reason you only ever get one entry in the $errorArray 
is that each key must be unique, otherwise you are just going to 
overwrite the old key.

I think you may want to use:

$errorArray[] = $additionalErrorArray;

instead of:

$errorArray += $additionalErrorArray;

or make the keys unique.

Dan

Phil Powell wrote:
> 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 )
> 
> 





More information about the talk mailing list