Skip to content

Instantly share code, notes, and snippets.

@breck7
Created August 31, 2009 19:50
Show Gist options
  • Save breck7/178666 to your computer and use it in GitHub Desktop.
Save breck7/178666 to your computer and use it in GitHub Desktop.
<?php
/*
easier way to deal with $_POST & $_GET etc: typecast it to an object.
$post = (object)$_POST;
benefits:
- quicker to type (30% faster to type $post->username than to type $_POST['username'])
- reduces chance of making syntax mistakes(you have to make sure to match 2 sets of tokens( ' and [ )in the former and 0 in the latter, reducing the likelihood of annoying syntax mistakes.
- easier to read?
downsides:
i have not researched the downsides, but they may include:
- efficiency (time spent typecasting and additional memory needed for object)
- security? (not sure if there would be any dangerous bugs here)
- clarity. I could see some people finding it easier to just use $_POST.
??
*/
$post = (object)$_POST;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment