FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Why is creating a PHP class useful?





jinger89
I've looked into the PHP class system several times in the course of creating my website, but I've never really found a use for it because I don't fully understand what they are and why they are better than just plain functions.

Can someone help me understand why classes are important? And when it's best to define one?
jmraker
Classes are useful in keeping functions organized into a group where they don't exist outside of it where you can define a class and create functions that manipulate it's variables like for a string class you'd have $string->toupper(), $string->tolower() instead of tolower($string) which can be used anywhere. In a project you can add the class and have the set of functions that you can count on with it. Without it, you'd have to check if the functions like a custom toupper() does what you expect.

If your site's code isn't too complicated you don't need to use classes.
rockacola
One may prefer having all his stationaries lying on his work desk, while other use drawers sorting and categorising his tools.

Question is: is one more efficient than the other? Wink
badai
when you have big, big project involving few programmers, each programmer will be assigned to do part of the project.

when a programmer was assigned to, let say handle a string and he provide function to change it to upper or lower case, then suddenly you also need the function to change it to title case. that is when class came in handy. only the programmer that handle the function will need to change his code. the rest just use it like nothing has happen.

but if you working alone on small project, it's kind of wasted, unless you are so used to it that you can't make any sense without packing everything in classes, or you want to learn using class.
badai
ahh... a clone of w3schools.com

maybe they work in advertising, just recycle other people's idea.
richard270384
I never understood the value of php classes until recently either.

They are great for large projects, but they are also good if you do multiple projects.

All my projects are based on the same php coding. I like to think of it as my own CMS.

I have a few classes which I use on my sites. I have a class for interacting with the session variable, MySQL, all my forum functions are in a class, user messaging system is in a class. Each class is saved in its own php file.

For me it just makes everything run smoother. If I find a bug in my mysql class I can fix it, and then just copy my mysql class file to my other websites. The problem is fixed easily just by overwriting the old file.

It's also good if I start a new project. Using my existing classes, half the php work is already done. I just copy the classes for the systems that I need and I know that everything is there.
jinger89
thanks for all the reply guys!

i think im starting to get a rough idea when and where to use a class, and i feel my project could use a little cleaning up and organizing with a class. and now to find the time to do it... Razz
pollux1er
richard270384 wrote:
I never understood the value of php classes until recently either.

They are great for large projects, but they are also good if you do multiple projects.

All my projects are based on the same php coding. I like to think of it as my own CMS.

I have a few classes which I use on my sites. I have a class for interacting with the session variable, MySQL, all my forum functions are in a class, user messaging system is in a class. Each class is saved in its own php file.

For me it just makes everything run smoother. If I find a bug in my mysql class I can fix it, and then just copy my mysql class file to my other websites. The problem is fixed easily just by overwriting the old file.

It's also good if I start a new project. Using my existing classes, half the php work is already done. I just copy the classes for the systems that I need and I know that everything is there.


Try to model a social network to understand how useful are classes and how useless are functions without classes into projects of such a scale. Wink
Related topics
Things that you MUST not SUGGEST -- READ BEFORE POSTING!
PHP Validation Class
Implementing your database access in PHP as a layer.
PHP Tutorials
PHP OOP Tutorial
PHP Tutorials
PHP newbie
An Example to mySQL class
PHP VS ASP
php error ?[parse error]
How to show a webpage preview/thumbnail a la ask.com?
Why not php 5?
Javascript and Dynamic Select Boxes
Read this before suggesting something!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.