Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4579

Re: Loading globals into classes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!not-for-mail
From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: Loading globals into classes
Date Mon, 23 Jan 2012 00:32:40 +0100
Lines 62
Message-ID <9o3kkoF541U1@mid.uni-berlin.de> (permalink)
References <jfhghn$rrn$1@dont-email.me> <9o38ofFagkU1@mid.individual.net> <jfi2kh$ege$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de 6nAojN9xD9SlZrTNql4G/QJDysyMJ/v7t4xrvpdxguZK/wqxU=
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.24) Gecko/20111101 Thunderbird/3.1.16
In-Reply-To <jfi2kh$ege$1@dont-email.me>
Xref x330-a1.tempe.blueboxinc.net comp.lang.php:4579

Show key headers only | View raw


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.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Loading globals into classes Scott Johnson <noonehome@chalupasworld.com> - 2012-01-22 09:20 -0800
  Re: Loading globals into classes "J.O. Aho" <user@example.net> - 2012-01-22 21:09 +0100
    Re: Loading globals into classes Scott Johnson <noonehome@chalupasworld.com> - 2012-01-22 14:08 -0800
    Re: Loading globals into classes Scott Johnson <noonehome@chalupasworld.com> - 2012-01-22 14:29 -0800
      Re: Loading globals into classes "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-23 00:32 +0100
        Re: Loading globals into classes Scott Johnson <noonehome@chalupasworld.com> - 2012-01-22 17:10 -0800

csiph-web