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?
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.
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.
ahh... a clone of w3schools.com
maybe they work in advertising, just recycle other people's idea.
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.