Jump to content

Pass POST value or POST name?


NotionCommotion

Recommended Posts

What does 'bla' do for you when you already have the POST value in hand? And what is '[]' supposed to represent? Plus your functions are not consistent. You pass in a name simply to use it in POST but then you hardcode a POST[index] in the function. If you are going to pass something to a function, keep your function generalized so that it may be used universally.

Link to comment
Share on other sites

What does 'bla' do for you when you already have the POST value in hand? And what is '[]' supposed to represent? Plus your functions are not consistent.

 

"bla" does something, and is not relevant to the question. "[]" is an array (you might want to look into it).  I believe the functions are consistent.

 

 

 

If you are going to pass something to a function, keep your function generalized so that it may be used universally.

 

Thank you.  This is very relevant.  So, you recommend the first as it is more universal.  Good point.  The second, however, reduces content of code assuming the function is used often.  Note sure if it is worth it, and thus why I am asking the question.

Link to comment
Share on other sites

Hard-coded $_POST references in the application logic are bad, because they tie your entire code to specific details of the HTTP protocol. Actually, it's even worse: You're tied to the low-level superglobals of vanilla PHP. What if you switch to a framework which has a different HTTP interface? What if you want to reuse the code in a different context? You cannot -- unless you manually go through your code and replace the superglobal mess.

 

Stuff like $_POST should only exist in the code which takes care of the HTTP details. Outside of that, you should pass values around and not make any assumptions about their origin.

Edited by Jacques1
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.