Page 1 of 1
Using PHP OOP
Posted: Wed Feb 03, 2010 8:08 am
by lshaw
Hello,
I was just looking for some advice on when to use a class in PHP instead of a function. Are they simply better to use than a normal function?
For example, if I wanted to connect to and select a database would I be better to use a class or function?
Thanks for your help,
Lewis
Re: Using PHP OOP
Posted: Wed Feb 03, 2010 9:28 am
by social_experiment
Personally speaking if you can get away with using just a function, use just a function. Otherwise its good to use a class, if you are going to use the same functions (methods inside a class) again and again. You could use a class and inside the class a method that connects to the database.
Re: Using PHP OOP
Posted: Wed Feb 03, 2010 9:34 am
by Eran
Use a class only when you understand how using a class helps you. Otherwise you gain nothing, you might as well use a function.
Re: Using PHP OOP
Posted: Wed Feb 03, 2010 9:37 am
by lshaw
thankyou for your replies
lewis
Re: Using PHP OOP
Posted: Wed Feb 03, 2010 5:46 pm
by Christopher
Use a function only when you understand how using a function helps you. Otherwise you gain nothing, you might as well use a class.
Re: Using PHP OOP
Posted: Sun Feb 07, 2010 4:31 am
by Luke
OOP is something that you will begin to understand the benefits of only after programming for a while. I'd just use what you are comfortable with until you are no longer comfortable with it. Good luck!