cleaning up my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

cleaning up my code

Post by d3ad1ysp0rk »

usually, if i have a bunch of things passed session or form-wise, i like to make them into normal variables, to make them easier to reference, like so:

Code: Select all

$id = $_SESSION['id'];
$page = $_GET['page'];
$date = $_GET['date'];
$amt = $_POST['amt'];
$type = $_POST['type'];
and so on. but that gets really tedious after awhile, and i remember finding a MUCH better way of doing it.

I believe it did something like run through each thing (post, get, session, etc) and then created a variable for each?.. but i have no idea how to do it, so i was wondering if anyone knows what im talking about

thanks
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Thanks, I use this if anyone wanted to know (or improve on it :P ):

Code: Select all

if(count($_POST) > 0){ extract($_POST, EXTR_SKIP); }
if(count($_GET) > 0){ extract($_GET, EXTR_SKIP); }
if(count($_SESSION) > 0){ extract($_SESSION, EXTR_SKIP); }
if(count($_COOKIE) > 0){ extract($_COOKIE, EXTR_SKIP); }
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

$_REQUEST ?
Post Reply