The main benifit (and aim) of using classes is that they are self-contained reusable blocks of code. For example, if I wrote a class to generate PDF files, you could then take that class, drop it into your www folder, and do something like:
$pdf = new Pdf();
$pdf->contents('some text here to put in your new PDF file');
No need to mess about copy/pasting code from my files to yours, or trying to fit the entire PDF generator into a single function.
Also, you could easily extend my PDF-generator class to include fuctions and features of your own without having to alter my original code. Your extended class could then be given to someone else who could use it without having to make a bunch of edits to my code to get it to work.
And finally, keeping your code in nicely organized self-contained classes makes them a lot easier to maintain on large projects
There are many other benifits but these are the most important ones to me.
A lot of people consider classes one of the most difficult things to get your brain around, but when you figure it out you will find it one of the easiest and straightforward things in PHP. The reason that many people don't at first see how it all works is that not everyone has used an OOP language before.
Classes are really just a box, containing variables combined with a set of related functions, from which you then create an object, so its really more like a blueprint or plan of an object, one way to think about it is as a car.
(NOTE: Dont confuse Classes with Objects, they are different. A class is a blueprint for an object, an object is created using the class as a guide, a blueprint for a house for example, a house is an object and it is created using a blueprint aka the class).
A car is a collection of wheels, doors, seats, windows, and so on. Another way to think about it is what a car can do: Speed up (Accelerator), Slow down(Brake), Stop, Park and so on. A class enables you to encapsulate, or bundle these variables and functions into one collection or 'box', this is called a class.
This has a number of advantages as a programmer, as everything you need to know about the car is in one place making development much quicker. Also when you become more advanced with your classes, you will have a premade libary of exsiting 'modules' or classes that you can just pickup and plugin to a new project, saving time by not replicating code. Also they allow the user of the class to have an easy to use API that they can call and not care about how the class works, consider a car's ignition cycle, i havnt the first clue of how it works, but because the ignition system was encapulated withing the car 'class' then all i have to do is turn the key and the rest, the car takes care of (hopefuly, unless its a french car, then it wont start at all, the key is our API in this example as are the foot pedals etc)
hope that makes sense, itskind of a stripped back explantion for now unil you get the idea :)
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
cool thanks for your descriptions it does seem like something i would use now.
whats a easy to understand book you would recommend i purchase to read more on this, i just finished a book by julie meloni called PHP Fast & Easy Web Development, 2nd Edition (Fast & Easy Web Development)