Following Object-Oriented PHP with Kevin Skoglund on

I've been working in Drupal 8 for a number of months (actually just about a year), but we just had a Drupal Meetup in Omaha, and it inspired me to try to get some PHP under my belt. The reason is this: while I spend a lot of my time with the front-end code, there are times when I'd like to be able to look into a module to see how it works. Heck, I'd even like to be able to write a module.

When I talked to @phenaproxima, who's a maintainer of the Lightning distribution of Drupal 8, about what you need to understand to really work in Drupal 8, he mentioned object-oriented PHP. He talked about a lot of other things, too, which you can see on the Omaha Drupal Meetup recording from November 2018.

Regarding the Skoglund, though, so far, so good.

I'm on Chapter 3, Extend and Override.

It's cool to be able to set different defaults to subclass properties than are in the parent class.

Anyway, I plan to continue it over break.

Then, I want to the Symfony 3 tutorial, getting ever closer to understanding how to actually do Drupal 8 as a developer.



Drupal Module Development with Jon Peck and the Paamayim Nekudotayim

We have all had that missing semicolon moment, when the entire app comes screeching to a halt because you hit return instead of semicolon and then return. The same thing happened today with “canvas”, which I spelled “convas” (not a word, apparently, and most certainly not one that Google Maps Drupal Plugin could use, when it was looking for canvas to be spelled correctly).

This led to an error with was really not right: “null is not an object.” Thanks, Javascript.

I swear I ran a diff on the PHP code I wrote and that of the exercise file but because of tabs and an extra return or two could not find the problem.

Instead, I grabbed the HTML output of my bad code from the browser and put it in TextWrangler. Then, I took the PHP from the exercise files and replaced my module PHP. Saved and lo! and behold, a map showed up. I grabbed the HTML output of that, compared the two front windows in TextWrangler and there it was: “convas” where “canvas” should be. (Update: later in the day, I had a very similar thing happen with a colon in place of a semicolon.)

“Where does he get all those wonderful toys?”

This is, of course, the best line in the 1989 Batman, said by Jack Nicholson’s Joker to his henchman. This is also what I’m wondering as I hear Jon Peck say that we need to use Drupal’s hook_block_info function. I can’t help but wonder how he knows that, because I know that I don’t know it, and I’m assuming he had to learn it. Did he do so by reviewing all of Drupal’s hook functions? That sounds crazy. Did he build a lot of sites and learn little bits of this stuff along the way? (Update: at the end of the tutorial he talks about how he spent time going through Drupal’s API, so I guess that’s not so crazy.)

Well, here’s a page about Drupal’s hooks, which I suppose is helpful, given that it was the top search result. It also contains links in the comments to the most used hooks, which is another bonus.


PHP Scope Resolution Operator (::) or Paamayim Nekudotayim

What I Learned

  • The name of ::
  • What other people call -> and =>

What I Knew

  • PHP (somewhat)
  • Drupal (somewhat)

As I was going through the tutorial, I couldn’t help but wonder why PHP uses the “->” to describe methods or properties of objects. In the process of looking around, I learned more about the Scope Resolution Operator or Paamayim Nekudotayim, which is used to describe the methods of classes, not objects. I had wondered why one was used sometimes and not the other.

Perhaps I don’t know the answer, but I know now that I’m not alone in wondering about these operators: