I noticed in a lot of scripts ( like phpbb ) that some functions are declared on the top of the script just to be used once. What the point of doing that? Are they used to make the code more readable?
For example I have a page that execute the user login, and the login is an action that can be done just there. So I declare a function for the login and I use it there.
Yes, more readable is usually the aim. And sometimes, to leave the option of re-using the code in future. Remember, a function is usually a bit of a black box: if you know how to use it, you don’t really care how it works, so it can help the programmer keep track of what would otherwise be a long block of code.
Edit: your login example is a good one. It’s entirely possible you’ll want to login from somewhere else in your site in future, in which case, having it as a function is a very good idea. Also, having
login($username,$password)is a lot clearer than a load of database lookup andsetcookie()bits.