2009/5/12 Ionut Gabriel Stan <ionut.g.s...@gmail.com>

> 2009/5/13 Ólafur Waage <olaf...@gmail.com>:
> > 2009/5/12 Brian Moon <br...@moonspot.net>
> >
> >> $foo = filter_input(INPUT_GET, "foo", FILTER_UNSAFE_RAW);
> >>
> >> That would have a value if set or null if not set.  It also allows you
> to
> >> validate it using filters if you wanted to.  This of course only works
> with
> >> GPC variables, but it is a great solution.
> >>
> >> Brian.
> >> --------
> >> http://brian.moonspot.net/
> >
> >
> > Can this be turned into a userland function?
>
> If you're interested in userland code, then you have two solutions:
> 1. Make functions like GET, POST, COOKIE, SESSION and use them instead
> of the superglobals (functions are superglobal). An example:
> ----------------------------------------------------------------
>
> // PHP < 5.3
> function GET($key, $default = null) {
>    return isset($_GET[$key]) ? $_GET[$key] : $default;
> }
>
> // PHP >= 5.3
> function GET($key, $default = null) {
>    return isset($_GET[$key]) ?: $default;
> }
>
>
> 2. Use ArrayObject to override the superglobals in an auto_prepend_file:
> -----------------------------------------------------------------
>
> $_GET = ArrayObject($_GET);
>
>
>
> Anyway, these will save the trouble with the superglobals, not with
> ordinary arrays.
>

Yes this will work with GPC variables but not with any other variable. And
passing values to it even feels right.

if(GET("foo") == "bar")


>
>
> >
> > Olafur
> >
> >
> >>
> >>
> >> On 5/12/09 11:35 AM, Ólafur Waage wrote:
> >>
> >>> While researching for this suggestion I found this rfc proposal
> regarding
> >>> ifsetor() ( 
> >>> http://wiki.php.net/rfc/ifsetor?s[]=isset<http://wiki.php.net/rfc/ifsetor?s%5B%5D=isset>
> <
> >>> http://wiki.php.net/rfc/ifsetor?s%5B%5D=isset>)
> >>> and it's rejection point was that it was currently not possible (
> >>> http://marc.info/?l=php-internals&m=108931281901389&w=2 )
> >>>
> >>> But would it be possible to check for a value of a variable if it is
> set?
> >>>
> >>> Since I often do (and see others do)
> >>>
> >>> if(isset($_GET["foo"])&&  $_GET["foo"] == "bar")
> >>> or even worse
> >>> if((isset($_GET["foo"])&&  $_GET["foo"] == "bar") ||
> >>> (isset($_GET["baz"])&&
> >>> $_GET["baz"] == "bat"))
> >>>
> >>> to be able to do something like this
> >>>
> >>> if(isset($_GET["foo"]) == "bar")
> >>> or
> >>> if(isset($_GET["foo"]) == "bar" || isset($_GET["baz"]) == "bat")
> >>>
> >>> That isset (or some other language construct) would return the variable
> if
> >>> it were set and false if it was not.
> >>>
> >>> Thanks for your time, i know this has probably been talked to death in
> one
> >>> form or other.
> >>>
> >>> Ólafur Waage
> >>> olaf...@gmail.com
> >>>
> >>>
> >
>
>
>
> --
> Ionut G. Stan
> I'm under construction  |  http://igstan.blogspot.com/
>

Reply via email to