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 #176766 is a reply to message #176760] Sun, 22 January 2012 22:29 Go to previous messageGo to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma:
Senior Member
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.
[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 06:46:49 GMT 2024

Total time taken to generate the page: 0.04392 seconds