[wp-trac] [WordPress Trac] #22325: Abstract GPCS away from the superglobals
WordPress Trac
noreply at wordpress.org
Fri Nov 2 22:41:17 UTC 2012
#22325: Abstract GPCS away from the superglobals
-------------------------+-----------------------------
Reporter: rmccue | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: General | Version:
Severity: minor | Resolution:
Keywords: |
-------------------------+-----------------------------
Comment (by CaptainN):
Replying to [comment:20 MikeSchinkel]:
The differences here are so minor, and there's no word on whether the
approach would be preferred or not in broad terms over the more robust OOP
based frameworks mentioned above, but let's keep going a bit more. :-)
> In my past where I went crazy with helper functions but learned that too
much is not a good thing; best to just stick with what exists.
Well in that case, why not just copy the 5 GPCS(R) array values, and call
it a day. It'd be easy enough:
{{{
$WP_GET = $_GET;
$WP_POST = $_POST;
// etc.
}}}
These wouldn't be super global, but they could be globaled, and then they
would work literally and exactly like the plain old superglobals. It'd be
the easiest for any PHP developer to pick up. But I think there's room to
improve things (I started with opposite position heh).
> > {{{
> > // vs:
> > if ( _GET( 'myVar', 'default value' ) != 'default value' )
> > // or:
> > if ( has_GET( 'myVar' ) && _GET( 'myVar' ) != 'default value' )
> > }}}
>
> You got that last one wrong. It should just be:
>
> {{{
> if ( _GET( 'myVar' ) != 'default value' )
> }}}
Don't think I did. If the value hasn't been set (eg !has_GET('myVar'))
then it'll pass the != 'default value' test because the value is NULL,
which is not what you want.
I did realize while playing with this stuff, you could use my _check and
_default methods even with the normal superglobals if I just suppress the
lookup error - what I did works exactly as an array lookup (returns NULL
if the key doesn't exist in the array). I think all we've really
accomplished vs the standard globalvars, is to not kick up a warning.
{{{
echo _default( @$_GET[ 'myVar' ], 'default value' );
}}}
> > And finally to output the value:
> >
> > {{{
> > // vs:
> > echo _default( _get( 'myVar'), 'default value' );
> >
> > // vs:
> > echo _GET( 'myVar', 'default value' );
> > }}}
>
> It's clear which of these I prefer. :)
Having the ability to set a default there does have some appeal.
Related, there is a hole in the model we've been discussing, which is
sometimes it's convenient to change the POST or GET data. Neither attempt
has a solution for allowing that. Adding it would seem to complicate
things.
Kevin N.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22325#comment:21>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list