FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Loading globals into classes
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Loading globals into classes [message #176771 is a reply to message #176768] Mon, 23 January 2012 01:10 Go to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma:
Senior Member
On 1/22/2012 3:32 PM, M. Strobel wrote:
> Am 22.01.2012 23:29, schrieb Scott Johnson:
>> On 1/22/2012 12:09 PM, J.O. Aho wrote:
>>> Scott Johnson wrote:
>>>
>>>> public function __construct($uom_ary, $months_ary)
>>>> {
>>>> $this->uom_ary = $uom_ary;
>>>> $this->months_ary = $months_ary;
>>>> }
>>>>
>>>> Previously I just used the global at the top of each method but had to
>>>> add it
>>>> for each method needing the array.
>>>
>>> Why not supply the information as arguments for the constructor.
>>>
>>
>> That seemed to work pretty well and seemed a bit less messy
>>
>> Here is what I did:
>>
>> In my array included file:
>>
>> $months_ary = array(
>> '1'=>'January',
>> '2'=>'February',
>> '3'=>'March',
>> '4'=>'April',
>> '5'=>'May',
>> '6'=>'June',
>> '7'=>'July',
>> '8'=>'August',
>> '9'=>'September',
>> '10'=>'October',
>> '11'=>'November',
>> '12'=>'December');
>>
>> $uom_ary = array(
>> 'Each'=>'Each',
>> 'Dozen'=>'Dozen');
>>
>> $global_arys = array(
>> 'Months'=>$months_ary,
>> 'UOM'=>$uom_ary);
>>
>> Then I instantiated the class:
>>
>> $processing_cl = new processing_class($global_arys);
>>
>> I can then pull the arrays out of the construct with func_get_args()
>>
>> Does that seem like a decent approach. Maybe I am over complicating this at this
>> time, but it is kind of good to know different ways of approaching different
>> situations if needed.
>>
>> Thanks again for idea.
>>
>
> Consider putting the whole array into the class without defining it outside, and put
> your code questioning it into the class.
>
> /Str.

Actually you bring up a good point. I have a static form class for
validating and displaying form elements. It would make sense to place
the definitions in there.

I do however like the idea of having a simple flat file to edit as the
client needs.

I used to have them in a DB but it seemed a little much.

Well either way I go, you all have given me some good food for thought.

Thanks for your time.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: list() Struktur auslagern
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 04:46:03 GMT 2024

Total time taken to generate the page: 0.04253 seconds