Jump to content
MakeWebGames

Functions


UCC

Recommended Posts

So I of course use functions where I can; it's good coding afterall.

But lets say you have a task that is as simple as Do Task X. However, you want confirmation

Would you make two functions? One for the Confirmation and One to do the task?

Or would you do something contained within 1 function

 

if (isset($_POST['confirm']))
{
}
else
{
}

 

Is one way any better than the other from a programer standpoint? Just a curiousity question that popped into my head. I usually do the latter on something simple like this.

Link to comment
Share on other sites

Re: Functions

I only use functions for things that need doing more than once... like error checking or something

Otherwise there's no point in using it, i just use if's as well, and you also dont need to declare variables as globals

I doubt it'll give much performance boost either way though

Link to comment
Share on other sites

  • 1 month later...

Re: Functions

I find it much easier to use classes/functions.

I'd make a class with misc. things like strip a string, things like that, and then make those as functions and put it in a class.

Whenever I need it I just include it.

I also find it very usefull when using ajax with it.

And the best thing with classes, it's everywhere, and you can find things you need very easily and fast. :)

Link to comment
Share on other sites

Re: Functions

Here is the superiority chain:

Functions <- PHP - MySQL

/ | |

Classes -> If <- Database

Then the other libs come in.

I mainly use it for everything, it saves allot of variable space, you write it once fluently, and then you just use it.

And I did mention you can get it easily, phpclasses.org

Edit: So yes.., the script I made you was if statements and not functions, but it's only for one time use.

Link to comment
Share on other sites

  • 2 months later...

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.   Paste as plain text instead

  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...