Starting OOP in PHP: Raspberry Pi Users Welcome!

oop1If Python Why Not PHP?

A couple of weeks ago, I finished up a MOOC course through Rice University. The course, An Introduction to Interactive Programming in Python, was taught by four Rice Ph.D faculty. I had no doubt that these guys knew what they were talking about, and they proved that assumption to be quite correct (and then some!). The 9-week course (about the length of a university quarter) was taught by making games. We started with a project Rock-paper-scissors-lizard-Spock and ended by creating the classic arcade game, Astroids. Initially, the programming centered around event-driven programming but soon introduced Object Oriented Programming (OOP).

So here’s an introductory Python course, where learning OOP is part of learning Python. I doubt many PHP programmers learned PHP using OOP, but why shouldn’t that be a preferred way to learn PHP? After all, once we’ve started using OOP, there’s a lot of programming practices associated with sequential and procedural programming that we’re urged to unlearn. Because OOP is foundational to design patterns, to effectively understand and use design patterns, you have to understand using an OOP model in creating PHP programs. So, after two MOOC courses, one from MIT and the other from Rice, I thought we could have our own MOOC (where the ‘M’ stands for ‘Modest’ instead of ‘Massive.’) By the way, I really need feedback on this, and if this is the best or stupidest idea you’ve heard all week, use the comment section to let me know.

As you can see, the discussion of programming on the screen looks pretty small, but you can blow it up or just look at the accompanying listings here on this blog.

<?php
//HelloWorld.php
 
class Hello
{   
 
    public function __construct()
    {
        $message = "Hello World!";
        echo $message;
 
    }
 
}
 
$worker = new Hello();
?>

If you’re a Raspberry Pi guy or gal, here are the links to Matthew Manning’s excellent videos on installing PHP and MySQL on your Raspberry Pi:

  • http://youtu.be/pamZ8EyXUCU <-- For installing PHP/Apache
  • http://youtu.be/n1vS2_-Xz9o <-- Install MySql

Don’t worry, though, this little project is in addition to the regular discussions of PHP design patterns; not instead of. So the next post on this blog will be the completed CMS series of posts using one or more a design patterns. Most of the Learning PHP OOP will be handled by the video. I’ll use the logo (at beginning of the post) to identify a post for this series so that if you already know PHP OOP, you can skip these OOP PHP tutorial posts and go to the next design pattern entry. By the way, the speed lines in the font and speedy symbols in the PHP OOP logo refer to the speed of development and re-use; not the speed of code execution.

So What’s Up with Raspberry Pi and PHP?

RaspPHPThis may sound convoluted, but here goes… A while back I learned about a little computer the size of my iPhone (see Figure 1) that came installed with Python. The computer has two versions—one for $25 and the other for $35. The idea behind them is that if kids got one, affordable even in poor countries, they’d become interested in programming. The goal is to encourage interest in computer programming; not just computer usage. Around the same time, a friend of mine working with Drupal at Arizona State University convinced me to take a wildly popular MOOC course in Python offered by Rice University. Finishing up an MIT Economics course in Global Poverty at the time, I was interested in taking a programming course. (The MIT course was fantastic, but I learned why Economics is called The Dismal Science.)

Figure 1: The Raspberry Pi can do OOP PHP for only $25

Figure 1: The Raspberry Pi can do OOP PHP for only $25

Awash in nostalgia and armed with Python, I got my own Raspberry Pi. I soon encountered an incredibly dedicated and active group of Raspberry Pi owners and advocates who all lived in a Yellow Submarine at http://www.raspberrypi.org. Also, I learned that some had installed PHP and MySQL on their little computers, and so I thought, here would be a great group to introduce to programming OOP and PHP simultaneously.

So now you know why I thought that introducing PHP and OOP at the same time is a good idea. Since one of the goals of Raspberry Pi is to get people interested in programming, why not start with OOP programming and any language; just like Python. PHP certainly has become an OOP language insofar as all of the right structures are in place. That’s been true since PHP 4 and even more so in PHP 5. Further, what’s true for learning OOP PHP for Raspberry Pi is true for all other programmers using PHP.

Now back to PHP design patterns…

Share

Copyright © 2013 William Sanders. All Rights Reserved.

0 Responses to “Starting OOP in PHP: Raspberry Pi Users Welcome!”


  • No Comments

Leave a Reply