The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Try out my first PHP web app! Reply To: Try out my first PHP web app!


Ok so if I do a return true at the end of the function, and then put it into use could I do something likeā€¦


A little confused in your Usage: section on why you passed $_POST into the function?

As a general rule, it is best to pass arguments you need into a function, rather than getting them from the global (or superglobal) scope. It makes it plain, just by looking at the function signature, what is needed for the function to work. It also means that you can be confident that you a working with the data you intended to work with. Some other, more practical benefits in this case:

  • you can test your function by passing “dummy” input instead.
  • you can accept form submission via other methods (e.g., GET instead of POST).
  • it is easier to do pre-processing (e.g., parse a JSON submission) on the input.