On Facebook, Josh McCall asked the group:

Any of you guys/gals know of a good tutorial or primer on PHP “classes”? Extra points if it’s WordPress specific, though I guess it doesn’t need to be.
Every time I try to read-up on them I just end up confused. Maybe it’s me, but I bet I just haven’t found the right tutorial or explanation yet.

Here’s an answer I wrote:

It’s probably not so much that you haven’t had the right tutorial, but (and this is just a guess) more likely that you’ve never worked with an application where they were very important. “Object Oriented Programming” as a metaphor for understanding how we design programs is a super simple concept, but unless you’ve worked with programs where it is the fundamental norm, the whys and hows of using it are still hard to see.

In WP, I just use them as containers/namespacing most of the time, which, whatever… they’ll do for that. Carl’s writing argues that there are better ways of doing that and he’s probably right. While there are a lot of objects in WP, it’s still (at least to me) doesn’t seem the fundamental paradigm most folks are using to work with WP.

But outside of WP there are other applications where OOP is much more interesting and important. Like, write a fairly simple Ruby on Rails app, and I think that a lot of OOP becomes a lot clearer… all the sudden having similar objects that you can pass around to other objects makes a lot of sense.

It sounds goofy and pointless (almost as annoying as a recommendation to start learning the CLI) but building stuff in other systems like Rails or Swing or Django taught me a whole dang lot and made me a lot better at building stuff in general, and that’s all had good applications for WP.

So here is my recommendation: if you want to learn PHP classes, build some stuff in a system that favors OOP. I like rails (learning Ruby isn’t super hard if you already know PHP and JS), but IIRC Symfony and Laravel are both more in that line and they are in PHP.

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *