I'll explain OOP in a different way, as I think it puts OOP into context and its benefits and how it works into a meaninful way. It might get a bit long, but it should help getting the OO concepts to make sense and how they are meant to be used.
Edit: Wow that got long...
I learned the basics of OO in the 90's using C++ for simple applications. Later I created a few basic Java Applets which were also OO.
Where I came to fully understand OO and where it all truly "clicked" was with a game engine called Unity 3D. I've used Unity since version 1 a fair few years ago, its a 3D game engine for desktop, browser based and now iPhone and Android based games.
In that environment OOP becomes essential as the applications are complex, they are real time and there is a hell of a lot going on; even in a simple game. So I'll explain OO in that environment and then PHP.
Consider a simple 3D game set across 10 levels with a playable character that has to navigate around a 3D area that contains monsters. I think monsters in games explain OO really well.
Each level will have many monsters, there will be multiple versions of the same monster that have different attacks, different strength, different defence and different AI behaviours.
Like say an Orc, some use an Axe and are physically strong, some use a bow and arrow, like to attack from range and will hunt you down.
They will have things in common as well; they both use the same mesh, maybe different textures, they will move the same way, they share some common skills, they detect you in the same way.
Here we have how OOP works and comes into its own...
You have a real time, 3D environment. You have two types of Orc (Axe Orc and Bow Orc). They are both orcs and if you created them as unique objects they'd share the same code (repitition) so you'd create an Orc Object (class) and have two child classes (Axe Orc and Bow Orc) inherited classes.
In OOP you can create parent classes and child classes that inherit everything from its parent. Like so:
Class Orc
{
... Behaviours that are common to all orcs regardless of type, i.e. the mesh, animation details, how they detect the player, base HP and defence ...
}
Class AxeOrc extends Orc
{
... Behaviours that are specific to Axe Orcs such as "Axe Blast" attack, additional strength modifier ...
}
Class BowOrc extends Orc
{
... Behaviours that are specific to Bow Orcs such as "Ranged Attack", additional agility modifier ...
}
In this example, using OO allows you to create an Orc class and then child classes for every type of Orc. This allows you to cut the size of the code down, have global behaviours contained in the parent and behaviours that are specific to a certain type of Orc in child classes.
This simplifies the code and reduces code repitition.
Using functional decomposition, this scenario would be more complex and you'd have code repitition:
function AxeOrc
{
... Behaviours that are common to all orcs, i.e. the mesh, animation details, how they detect the player, base HP and defence ...
... Behaviours that are specific to Axe Orcs such as "Axe Blast" attack, ...
}
function BowOrc
{
... Behaviours that are common to all orcs, i.e. the mesh, animation details, how they detect the player, base HP and defence ...
... Behaviours that are specific to Bow Orcs such as "Ranged Attack" ...
}
In this example the two functions are almost identical with subtle differences. You have a lot of code repition.
Now lets say you wanted to add a new skill to ALL types of Orc. In the OO example you'd add the new skill to the Orc class and all child classes would automatically gain that skill.
In the functional decomposition example you'd need to add the skill to ALL of the Orc type functions.
Also in OOP the functions for Orc's are contained within the class which nests them together in a tidy little package.
So class Orc would have a bunch of functions for Orc that only Orc objects can use.
The child classes would contain a bunch of functions that only say AxeOrc can use.
Now consider this, you have "grunts", some of them have an Axe and have an attack called "Axe Blast", but its totally different from the Orcs.
In OO you'd have:
class Orc
{
}
class AxeOrc extends Orc
{
function AxeBlast()
{
}
}
class Grunt
{
}
class AxeGrunt extends Grunt
{
function AxeBlast()
{
}
}
There you have two functions of the same name in two different classes, in functional decomposition you'd have:
function OrcAxeBlast()
{
}
function GruntAxeBlast()
{
}
This is messier.
Now for another concept, instantiation. In OO you can create unique instances of an object (class). So you can create say 10 instances of AxeOrc, they are all unique, independant instances. This is a major concept especially in a real time application where you have have multiple instances of the same object appearing, disapearing and reapearing in different places.
Then different instances can have slightly different behaviours themselves, say different route finding etc.
I think the benefits of OO speak for themselves here, although its a simple "application" it is quite complex and performing these operations using functional decomposition would be very, very messy.
It's this kind of scenario that OOP was devised to tackle. Scenarios where you have multiple instances of the same object, behaving in different ways and being independant of one and other in a real time or semi-realtime environment where stuff is changing a lot.
Even in a game using Unity you're not ALWAYS using OOP, you have functional decomposition too. Some things lend themselves to OOP and others to Functional Decomposition.
Also consider a full game, how much is going on, the massive amount of variables and data thats being passed around, how many objects are appearing, how many different types of object appear and how you have "variants" of the same object or objects that share common functions.
OO lends itself to this scenario.
PHP is different, for one it is by design procedural (hence why I used the term functional decomposition). Even an OO application in PHP is procedural, its not that fluid and is not ever changing, its all pre-processed and ran through procedurally.
It's also rarely having to deal with incredibly complex problems, at least not in the same way as a game or big desktop application like Adobe Photoshop.
In things like games or big desktop applications there are lots of scenarios where functional decomposition either doesn't work or doesn't work well. There is almost always a way to do it, but that way is going to be a hell of a lot more complicated and repetative. The code will also not flow as well.
Also some myths...
1. OO does not make cleaner code, Functional Decomposition does not make messy or spaghetti code. You can have clean, easy to read, well formed code using both methods. You can also have messy, spaghetti code using both methods. Thats all down to the programmers, how they structure the application and how well designed the application is.
2. OO does not make code read better, Functional Decomposition does not make code read poorly. This is entirely down to how the programmers name their classes or functions. Both OO and Functional Decomposition can be virtually unreadable, they can also be very readable and self explanitory.
3. OO does not remove code repitition, Functional Decomposition does not create repitition. This too is down to the programmer. Using both OO or Functional Decomposition you can have repitition or reusable classes/functions.
4. OO does not make code extendable, Functional Decomposition does not make code difficult to extend. Again its down to design and how the programmers create their classes and functions.
However in certain environments such as games and complex desktop applications using OO lends itself to making code cleaner, more readable, less repetative and more extendable provided the application is well designed. Functional Decomposition in certain environments (such as the Orc example) would lead to repitition and poor naming convention, extension would require changes in many placed by default.
If we consider a PHP application, even a complex one like a forum, if your application is designed well and you consider readability and code structure then you're not really going to gain all that much from OOP over Functional Decomposition. Not in any real, quantifiable terms anyway.
There are no technological benefits with PHP applications, code can be very readable either way (or unreadable), code can be reused and extended easilly either way (or un reusable and unextendable).
This is because, quite frankly most PHP applications just are not that complex, not in comparison to say Adobe Photoshop or Grand Theft Auto IV. There is a lot less going on, things are way more linear, things are not ever changing, you don't have that many variations of the same thing with broad behaviour differences, functions just aren't ever that big (a complete monster controller in Unity with full AI & pathfinding would make wordpress look like "hello world").
Take a blog, you dont NEED OOP to make it work well, be structured well, flow well, be meaningful, be extendable etc. etc.
i.e.
Users, quite simple, even with user groups.
Categories, again quite simple, little variation.
Blog Posts, again very simple things with little variation.
Comments, again very simple with little variation.
You don't have many types of blog post or category or comment or user with many different behaviours, things don't suddenly appear as the application is preprocessed. In this environment OOP does not really give you anything.
That said, I use OOP, but not in a pre sense. Our internal framework for example uses OO for the folloing things:
1. The bootstrap that ties everything together
2. Database connectivity (as that supports multiple types of database)
3. The template engine
4. Users and usergroups & permissions
These don't even need to be in OO though, the functional version is just as readable, just as extendable and performs much the same way. In fact the code looks and is structured very similarly (mainly due to how the functional decomp version is structured deliberately to be reusable and extendable).
We use then create new classes for complex datasets, but not for functionality all the time. Its just needed nor beneficial.
Having an OO platform doesn't give us anything over functional decomposition.
So bottom line, your choice. Its PHP, a procedural, preprocessed scripting language used for what are in effect simple web based applications. Go with what you will do a better job with.
Sometimes however the application will have specific features that lend themselves to OO, that does not mean the whole thing must always be OO. It also does not make you a bad or amateur programmer if you don't use OO.
It would if you were making a game in Unity or a complex desktop app, but not in this environment as its not required and you don't gain anything from it.