Re: Passing Super Globals to functions



Scott Johnson wrote:
Passing the Super Global to a function:

myfunction($_POST);

function myfunction($post) {
/* use $post */
}

or calling the Super Global directly in a function

myfunction();

function myfunction() {
/* use $_POST */
}

I have not run into a problem yet and I have seen myself use both ways. Just curious if someone has information on the preferred way for security.

Thanks
Scotty

It depends.

You can use the second one if your function will ALWAYS get its information from the $_POST array.

However, most of the time you can't guarantee this, especially if the function is generic (which it should be, as much as possible at least). For instance, another time you might want to get the data from the $_GET array; or maybe $_COOKIES, or possibly even your own home-built array.

The first way allows for such operations, which makes it more flexible and generic. It's not really a matter of security, as others have indicated. But it does make the code more reusable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.