0

In risk of sparking an opinionated discussion I ask the following:

Is it considered bad practice to re-declare $_POST and $_GET variables inside a PHP script?

I.e.

$_POST['var'] = 'someValue';
$_GET['var'] = '';

The reason is emptying variables on certain instances and thus avoiding reloading page and risk of sending headers multiple times.

3
  • 1
    The question would be what are you doing wrong to warrant changing the values of globals in your script. Commented Apr 7, 2013 at 19:40
  • 1
    If you "need" to do this, then there's probably a bigger issue elsewhere... Commented Apr 7, 2013 at 19:41
  • 1
    How come an emptying variable would help to avoid risk of sending headers multiple times? Commented Apr 7, 2013 at 19:42

3 Answers 3

1

Yes, it's bad practice. You can achieve what you need maybe with a hidden input which gets a certain value in the event you want to ignore the $_GET or $_POST variables.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, I often do this myself, and it's also how Wordpress often solves this issue, so it's not a bad option.
0

Yes it is bad practice, because it changes what others are expecting of these variables.

Debugging can become quite a hell if you start doing this kind of stuff.

Comments

0

The reason is emptying variables on certain instances and thus avoiding reloading page and risk of sending headers multiple times.

There is a pattern called the PRG Pattern which has been made to avoid the re submission of data on page reloads.

1 Comment

What does PRG have to do with manually modifying superglobals?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.