OOP and PHP

Silver-0-surfer

Well-Known Member
Joined
Jan 5, 2008
Messages
317
Reaction score
7
Location
CPT
Hi Guys

I have been using php for a while now, I work in a smallish company and we don't have our developer (we dont do that much web based stuff, but we do some) so I picked up php and started learning it. Mostly its been pretty simple stuff.

But i'd never been programming before so i'm really getting into it as sort of a hobby. So now i'm wondering about Object Oriented Programming. I read some documents and watched some videos on it, and I understand the basics. The thing is I can't wrap my head around how its useful and what the benefits of it are over procedural based php (with functions)?

Does anyone know of a place where I can download a free web app or something that someone has written, just to see it in action? I know im taking a long shot, but I really want to check it out.
 
The benefits? There are arguments both for and against.

In general, it's supposed to promote reuse of code. Another benefit (in some situations) is that it's often easier to think in terms of objects and messages passed between them.

Yet thinking in this way, while sounding intuitive, often causes a lot of confusion. And knowing exactly what's going on behind the scenes can take a lot of work. All this thinking about the problem takes time away from actually getting code down to solve it.

So ya, a touchy subject sometimes.

I'd say you should either just read up on some applications of OOP, or get yourself a book. If you're looking for existing implementations, there are plenty of projects available on Sourceforge. But if you're still starting out, you kind of need to get to a certain point (different for different people) before you can truly benefit from others' code.
 
I guess the main issue is I don't have anything to do, i.e. a new project to work on, to try and implement it and see it working in real life.

I really hate books, but it looks like it must be done.

Thanks
 
I guess the main issue is I don't have anything to do, i.e. a new project to work on, to try and implement it and see it working in real life.

I really hate books, but it looks like it must be done.

Thanks

Doesn't have to be a new project? Usually, grasping new concepts is easier when you're familiar with the application. So you could try refactoring old projects.
 
Perhaps you could take an existing website and convert it to an OOP framework, like SilverStripe, tgat forces you to create your own classes. You could go through the source code, and the tutorials, then make your website. That may be a good way to grasp the concepts...
 
I guess the main issue is I don't have anything to do, i.e. a new project to work on, to try and implement it and see it working in real life.

I really hate books, but it looks like it must be done.

Thanks

write a game! :D
 
There's lots of good open source OOP code available out there.

Checkout out Zend Framework 2.0 (https://github.com/zendframework/zf2).

Plenty to go through there. Reading through the roadmaps and changelogs will also give you a good insight into practical design patterns and decisions.
 
Maybe try refactoring an existing project/site you have. Is the database code spread out everywhere, try putting the database connection in a database object. Then move code related to specific things into their own objects that use the database. Eg a if you have authentication, maybe a user object that queries the database object for its info, and updates etc. Now you have your database and model code neatly separated. You could then look for other areas of repetition and make that object oriented. Is the navigation code repeated, you could encapsulate that logic in an object/objects. After you get the hang of it, you should then look at one on the frameworks to see how they do it. I would second Zend Framework. Also have a look at PEAR (pear.php.net) which has lots of useful libraries you could look at, most of them are OO.
 
Top
Sign up to the MyBroadband newsletter
X