[wp-trac] [WordPress Trac] #22325: Abstract GPCS away from the superglobals
WordPress Trac
noreply at wordpress.org
Fri Nov 2 17:37:16 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: |
-------------------------+-----------------------------
Changes (by MikeSchinkel):
* cc: mike@… (added)
Comment:
Replying to [comment:11 CaptainN]:
> I was thinking something a bit more simple, a set of functions that
mimic the GPCS globals.
>
> {{{
> // instead of
> $something = $_GET['something'];
>
> // use the new
> $something = _get('something');
> }}}
+1.
Suggestions:
1.) It would be great if we could finally get away from this pattern:
{{{
$foo = isset( $_GET['foo'] ) ? $_GET['foo'] : false
}}}
and instead be able to do ''(something like)'' this ''(which defaults to
100)'':
{{{
$foo = _GET( 'foo', 100 );
}}}
And maybe this defaults to `null`:
{{{
$foo = _GET( 'foo' );
}}}
2.) If it supports defaults we need a way to test for existence, and we
could do this:
{{{
if ( ! has_GET( 'bananas' ) )
echo "We have no bananas today.";
}}}
3.) We might need to test count of $_POST to see if a form was submitted,
so passing no parameters to has_POST() could do that:
{{{
if ( ! has_POST() )
echo "No form submitted.";
}}}
4.) For accessing multi dimensional arrays we could pass in an array of
keys instead of a string or numeric key:
{{{
// For <input type="text" name="test[abc][123][xyz]" />
var_dump( _REQUEST( array( 'test', 'abc','123','xyz' ) ) );
}}}
5.) The examples above use uppercase for _GET() and _POST(); those would
be more consistent with the existing vars than using `_get()` and
`_post()`, be easier to see in code, and probably be less likely to
conflict with existing code.
'''I've implemented and ''(mostly)'' commented `_GET()`, `_POST()` and
`_REQUEST()` in a self-contained attached example file `GPCS.php`'''. You
can drop in to the root of a WordPress site to test and play with. I
didn't have time to implement the rest of the superglobals but might work
on them if people like this approach.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22325#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list