A question for php devs who work for a company

I have done a few small sites / apps in php just using good old functions and 'procedural' code.

I think OO should be better but I just can't seem to get a hang of it, most examples I look at are so simple, I'm sure they aren't giving me the benefit of why I'd do it thatway. I can't get how everythign hooks together in a OO setup. When thinking about a problem I just naturally think in routines/functions anyone got a good resource to convince me?

oth codeigniter looks good, but then viewing the vids above, what do I do when I want to use slightly more advanced queries than . get_all_records('data') etc?
 
I have done a few small sites / apps in php just using good old functions and 'procedural' code.

I think OO should be better but I just can't seem to get a hang of it, most examples I look at are so simple, I'm sure they aren't giving me the benefit of why I'd do it thatway. I can't get how everythign hooks together in a OO setup. When thinking about a problem I just naturally think in routines/functions anyone got a good resource to convince me?

oth codeigniter looks good, but then viewing the vids above, what do I do when I want to use slightly more advanced queries than . get_all_records('data') etc?

Most of these frameworks provide some kind of abstraction from the plain sql they execute just to allow those with limited sql skills to still knock up applications. They usually have a plain execute command that has similar functionality to just executing sql but with a few extras so have a ganders for that.

I think that in a lot of cases you will find that picking up one of the simple OOP frameworks will be the best way to learn.
 
I have done a few small sites / apps in php just using good old functions and 'procedural' code.

I think OO should be better but I just can't seem to get a hang of it, most examples I look at are so simple, I'm sure they aren't giving me the benefit of why I'd do it thatway. I can't get how everythign hooks together in a OO setup. When thinking about a problem I just naturally think in routines/functions anyone got a good resource to convince me?

oth codeigniter looks good, but then viewing the vids above, what do I do when I want to use slightly more advanced queries than . get_all_records('data') etc?

I agree that those "dog extends animal" type examples are not very useful for demonstrating the real world advantage of using objects or how you might implement them.

Of course there are many advantages (and some disadvanages) to OOP but some of the main ones are; code re-use, readability, maintenance.

I'm assuming you have some projects which involve user login? As an exercise, try taking all the user functionality and re-writing it in an OOP way. You will need at least two classes

1) class auth
2) class user

For Auth, you will probably want to use a Singleton design pattern, because you will only ever want one instance of this class. Auth should have methods like:
forceLogin((object) $user), login($userName, $password), logout(), getUser().

I'm purposefully being quite vague here as all the info is already out there :)

In the end you should be able to do things like:

$user = new user('superhans66'); //load from a database
$user->status = 'divorced'; //change some property
$user->save(); //update database

if (auth::instance()->forceLogin($user)) echo "you are now impersonating $user->userName";

Once you have good collection of base classes, you will be able to quickly role out new projects because the vast majority of web apps have the same sort of functionality. You just need to extend the base classes, adding only the specific new features you require. This is basically all frameworks are about - abstracting repetitive tasks in web development.

Also most frameworks encourage good design patterns and conventions such as MVC, although normally they are not strictly enforced most of the time.
 
Ok good answer . I'm actually going to redo a couple of my apps using code igniter to hopefully see what's what. I can also try to rewrite my login and user handling functions
 
While I'm not convinced codeigniter is that good for learning OOP, it is probably the right choice due to the excellent docs and community. Think about switching to kohana as soon as you are on your feet.
 
Back
Top Bottom