Re: switch-statement overrides use of global arrays?
| From: | DL Neil | Date: | Sun, 28 Oct 2001 22:25:32 +0000 |
| Subject: | Re: switch-statement overrides use of global arrays? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72649@lists.php.net to get a copy of this message | ||
Imar,
The global array is being defined in the mainline, but not populated. What happens if you set
element 0 to some
value (to take up some storage space first) and then try the switched function calls?
When you say "Alas, this also emptied the array each time I went from one function to another
via the switch
statement." do you mean that the array definition line is inside the same loop that causes the
switch statement
to be revisited?
(it shouldn't be - put it right at the beginning of the 'mainline' and ensure that it
is not re-executed (which
would indeed 'reset' the values))
Regards,
=dn
----- Original Message -----
From: "Imar de Vries" <I.O.deVries@students.let.uu.nl>
To: <php-general@lists.php.net>
Sent: 28 October 2001 21:49
Subject: Re: [PHP] switch-statement overrides use of global arrays?
> Henrik Hudson wrote:
>
> > I would think you would need to define $array_test outside in a "global"
> > environment rather then inside the function since I think/thought it will
> > just stay scoped in there and that "global" was used to access variables
> > which weren't defined inside a functions scope and make it look outside.
> >
> > In other words
> >
> > //Define GLOBAL
> > $array_test = array();
> >
> > switch(){
> > BLAH
> > BLAH
> >
> > }
> >
> > function main() {
> > global $array_test;
> > BLAH
> > BLAH
> >
> > }
> >
> > function test_one(){
> > global $array_test;
> > BLAH
> > BLAH
> >
> > }
>
> Yes, the only way I could avoid errors that occurred when I tried to manipulate
> the array, was to add a $array_test = array(); a few lines before the switch
> statement. Alas, this also emptied the array each time I went from one function
> to another via the switch statement.
>
> I guess I am trying something that is just not possible (when I insist on using
> the switch statement)?
> --
> Imar de Vries - I.O.deVries@students.let.uu.nl - ICQ 6972439
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>