OOP! There it is. OOP! There it is.
April 23, 2009 5:35 PM   Subscribe

I'd like to sharpen my PHP skills and finally tackle OOP, classes, etc.. There's an overwhelming amount of tutorials online, so I was wondering if you had a favorite one (or ones) that helped you hone your OOP skills.

I've tried going straight to the source on PHP.net's reference material, but I'd ideally like something a bit more dumbed down. Once I get a grasp on general concepts, I'll definitely go back and check out the PHP toot, but for now I'm looking for something a bit more accessible. Thanks!
posted by bjork24 to Computers & Internet (7 answers total) 11 users marked this as a favorite
 
While I'm afraid this may just confuse you in the short term, keep in mind that OOP is a somewhat vaguely defined concept, and consequently many tutorials will seem to be talking about something completely different from each other. Ideas and techniques that would be considered the epitome of OOP in Smalltalk or Ruby will seem to have little in common with the way it's typically used in Java or C++, and vice versa. (OOP doesn't require classes, either... Look at Lua or Javascript.)

I don't know PHP, but in the short term, this means you'll probably want to look for PHP-specific tutorials. In the long term, Python has a relatively conventional OO system, but without Java/C++-like static typing annotations, which will only get in the way when you're trying to pick up the main OO concepts. Once you have a handle on how it works in Python, you will probably be able to generalize to other languages relatively quickly. (Python is also a pretty good language, FWIW.)
posted by silentbicycle at 7:58 PM on April 23, 2009


I'm a web developer who uses PHP every day of my life, and I had to make the transition up to objects recently. If you know a language like Java, learning will be a whole lot easier. Java's handling of abstract methods and interfaces is pretty close to what PHP does; the only thing that's not handled so well in PHP, IMO, is polymorphism.

It sounds kind of lame, but you may want to give the Wiki article on OOP a shot. I can't really think of any books that I used to learn OOP, but that was mostly because my classes had forced me into learning it.

Personally, I learn better by doing things hands on. To that end, one other thing you may want to do is learn the objects within the context of an application. To this end, I'd recommend downloading the Zend Framework and working with it. It's entirely class-based, so you'd have to write classes and functions and all sorts of fun. Zend's documentation is also really good (especially their Quickstart), so that would make things that much simpler.
posted by gchucky at 9:59 PM on April 23, 2009


The hard way (but you'll learn deep stuff): go through chapters 1, 2, 3, 6 and 7 of Concepts, Techniques and Models of Computer Programming there's a draft version floating on the interwebs.
posted by Monday, stony Monday at 10:38 PM on April 23, 2009


I'm by no means a particularly good programmer, but something I've found helpful is to go back over old projects I've done and redo them every time I learn some new skill. This is better for me than working out of a book, because in a book I just end up reading their code and never really writing any of mine. But by working on one of my programs, I can't cheat.

I'll do this when learning new languages, as well; there are some problems that are so generic you can accomplish them in almost any language. So once I feel like I've gotten the hang of a new language from reading the documentation or a book, I'll open up some little utility and try to rewrite it in the new language.

Since it sounds like you have some stuff written in PHP, that's the route I'd take. Learn a little, and as soon as you feel like you're getting the idea, make a copy of an old project (one that you feel like you really comprehend completely) and work the new idea into it. If you're anything like me, you'll probably run into a roadblock where you really don't know the new feature as well as you thought, and then you can fill in the gaps as needed.
posted by Kadin2048 at 12:09 AM on April 24, 2009 [1 favorite]


The book Monday, stony Monday recommends is fantastic if you're a career programmer, though probably a bit much if you're just putting together a website or something. It's a big book, and quite deep (much like SICP, though in a different direction).

Another thing with OOP is that some of the ideas in it won't make much sense unless you're working with a team of programmers and/or on a large project.
posted by silentbicycle at 8:02 AM on April 24, 2009


As a former PHPer*, I'd strongly recommend learning your way around objects with a new language. Learning a new language is not as hard as you might think -- if you're at the level where it's appropriate to start thinking about OO, you're at the level where picking up a new language will be surprisingly easy. I'd recommend Ruby or Python, since it's probable you do web development and you'll be able to immediately apply either one of those new languages. The general idea behind objects is pretty simple -- what you need to figure out is how to use them. For the most part, that means patterns. I cringe at the idea that I'm actually going to recommend this book (because it's basically a 'dummies' guide, with big print and a ton of pictures), but check out: Head First Design Patterns (at your library -- they'll probably have it). It's a super dumbed down overview of the Gang Of Four patterns, which I found fairly tough to consume. It'll blow through the general idea behind OOP fairly quickly, and then tell you how to use it, which is the most important part. Most OO patterns are pretty non-intuitive but immediately apparent as brilliant.

This is also a super-good time to learn about TDD. Test driving will make you a better programmer, and after learning how to do it, you'll be surprised that anyone ever coded without tests. Ruby/Rails has test driving baked in (and accomodates many other good programming habits, like simple support for version control and deployment). If you need a space to throw down some rails, I'd recommend dreamhost -- you can get super-cheap rails hosting for the (first) year for around $10 -- it's also a great place to drop subversion repositories. If you end up doing Rails, I *highly* recommend using Rubymine -- it's one of the best IDEs I've ever used (even though it's still "in development" and has a crapload of bugs, and probably will have a crapload of bugs when it's "released").

You can do all of this with PHP too, I'm sure -- I have no idea what the tools are like, but I'm sure they're there.

* And by former, I mean "NEVAR EVAR EVAR AGAIN". I've never seen a PHP project that's not spaghetti code, and I say that having built several of these messes myself.
posted by fishfucker at 7:57 AM on April 25, 2009


er, to clarify, I'd recommend Ruby or Python because objects are baked in from the start, so it might make more sense than PHP's OO language features.
posted by fishfucker at 12:12 PM on April 25, 2009


« Older Do other computers fear the Chicago Machine?   |   Is there an atheist version of "God Bless You" or... Newer »
This thread is closed to new comments.