Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:00:02+00:00 2026-05-29T06:00:02+00:00

This is a style question, I suppose. Why do people go through the trouble

  • 0

This is a style question, I suppose. Why do people go through the trouble of assigning a variable with $_GET and $_POST data in PHP? For example, why do this:

<?php
    $name = $_GET['name'];
    echo $name;
?>

when you can just do this instead?

<?php
    echo $_GET['name'];
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:00:05+00:00Added an answer on May 29, 2026 at 6:00 am

    There are several reasons:

    1. It’s easier to write, especially when including inside a string.

    2. You only have to sanitize it once and know that whenever you’re calling the interim variable it is the sanitized version.

    3. (this is a big one) $_GET and $_POST variables are available globally, which means that multiple functions or statements may depend on its value. If you ever need to modify a variable ($_GET[‘var’]++, for instance) it may be important that you are not affecting other functions. Thus it’s safer to store the value in a working variable in case the $_GET or $_POST variable ever gets used in another place.

    4. If you have to access the variable multiple times, reading it out of the array each time will be slower… I’m tempted to leave this out of the list altogether, as the difference is so vanishingly small, but when some people optimize large loops they will store the variable outside the array. However, even after hundreds of thousands of reads the speed difference may not be noticeable, so it’s not a particularly compelling addition to the list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a minor style question, but every bit of readability you add to
(Jeopardy-style question, I wish the answer had been online when I had this issue)
This is a classic sort of question, I suppose, but it seems that most
This is a question about coding style and recommended practices: As explained in the
This isn't a style question. Its more about the proper use of the language
This is more a style question. For CPU bound processes that really benefit for
I suppose this might be similar to this question , but I'm wondering if
My question is simply: is it even possible? Suppose I want to style a
Disclaimer: This question is strictly academic. The example I'm about to give is probably
Is there a good reason (advantage) for programming this style XmlDocument doc = null;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.