Re: Code Advice
| From: | Kevin Stone | Date: | Wed, 06 Nov 2002 19:30:22 +0000 |
| Subject: | Re: Code Advice | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123054@lists.php.net to get a copy of this message | ||
It's probably working becuase you have register_globals = ON in your php.ini
and those variable names are being set by default. Your posted code is
actually doing nothing. What I can't figure is why you're not getting any
errors. :-\
-Kevin
----- Original Message -----
From: "Jason Young" <jason1@erols.com>
To: <php-general@lists.php.net>
Sent: Wednesday, November 06, 2002 12:13 PM
Subject: Re: [PHP] Code Advice
> Hmm..
>
> So then can anyone tell me why its working so far? ;)
>
> I am trying out every single function in this page in hopes to catch
> something, but so far I don't see any breakage - I can see there are a
> few ways to skin this cat.. the original code I posted DOES work.. I
> still may be blind to any future breakings.. that's why I posted it.
> Unfortunately, I'm getting responses saying that this code won't work
> at all - when it does.. :-/
>
>
> Mike Ford wrote:
> >>-----Original Message-----
> >>From: Kevin Stone [mailto:kevin@helpelf.com]
> >>Sent: 06 November 2002 18:50
> >>To: php-general@lists.php.net
> >>Subject: Re: [PHP] Code Advice
> >>
> >>
> >>All I have to go by is what I see. The method was this..
> >>
> >><?
> >>$get_allow = array('foo', 'bar', 'add',
> >>'takeovertheworld');
> >>
> >>while (list($key,$val)=each($get_allow))
> >>{
> >> if (isset($_GET[$key]))
> >> $$key = $val;
> >>}
> >>?>
> >>
> >>The array $get_allow has numerical indicies. Looping through
> >>that in the
> >>method described is going to set an integer to $key. So your
> >>first error is
> >>going to be that $_GET[0] is Undefined. Second error is
> >>going to be $$key
> >>is an invalid variable name.
> >
> >
> > Mea culpa -- you're quite right, and I should read more carefully!
(Well, it is 7pm and going home time....)
> >
> > This should, of course, be done like this:
> >
> > $get_allow = array(......);
> >
> > foreach ($get_allow as $key):
> > if (isset($_GET($key)):
> > $$key = $_GET[$key];
> > endif;
> > endforeach;
> >
> > Cheers!
> >
> > Mike
> >
> > ---------------------------------------------------------------------
> > Mike Ford, Electronic Information Services Adviser,
> > Learning Support Services, Learning & Information Services,
> > JG125, James Graham Building, Leeds Metropolitan University,
> > Beckett Park, LEEDS, LS6 3QS, United Kingdom
> > Email: m.ford@lmu.ac.uk
> > Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>