Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How come when I use var_dump($_REQUEST); I can get an array of elements, but the php documentation said I can't...?

In the PHP Manual ( http://ca3.php.net/manual/en/reserved.variables.request.php), I found this code

<?php
$_GET['foo'] = 'a';
$_POST['bar'] = 'b';
var_dump($_GET); // Element 'foo' is string(1) "a"
var_dump($_POST); // Element 'bar' is string(1) "b"
var_dump($_REQUEST); // Does not contain elements 'foo' or 'bar'
?>

I was able to get an array with the elements when I used var_dump($_REQUEST) though.

3 Answers

If you do

$_REQUEST['foo'];

will it give you foo (value of 'a')?

I just checked out the comment you read (remember these are user-added comments, which although trustworthy are not from the php docs themselves)

"Don't forget, because $_REQUEST is a different variable than $_GET and $_POST, it is treated as such in PHP -- modifying $_GET or $_POST elements at runtime will not affect the ellements in $_REQUEST, nor vice versa."

This poster is referring to these variables in the contect of modifying at run time.

I didn't know those comments were from users, I thought it was from the documentation?? A prof told me $_REQUEST is $_GET and $_POST together. Or should I think of $_REQUEST and a separate php variable all together?

Anything under the section heading "User Contributed Notes" are comments from users. I believe they're validated and also voted up/down.

They're all totally separate variables. $_REQUEST also included $_COOKIE.

I prefer to use "print_r" which is more readable by humans.

print_r($_REQUEST);

And of course, it should display both content of $_GET and $_POST; except if $_GET or $_POST are changed by your code (which should not be the case).