OOP in PHP Primer: Get your First Taste of Classes, Constructors, and Methods

Are you a PHP programmer who is yet foreign to the concept of Object Oriented Programming? Are you looking for an article, or tutorial to recommend to a friend so he or she might become better acquainted with the OOP style? If so, I know a very nice little article which I recommend for getting the feet wet with Object Oriented Programming in PHP. Check out โ€œClasses and PHPโ€ (updated link here) by Rod Kreisler, as published at one of the definitive PHP community forums, PHPBuilder.com

Exemplary Learning Material:
Developing a Model for Efficient Studies

I decided that my own commentary on the article Classes and PHP, instead of being a play-by-play of the article itself, would be a study of how to make the most of a good resource, such as the PHPBuilder.com article cited here.

The article, Classes and PHP, which starts off with very easy-to-understand explanations, in plain English using real-world analogies, goes on to provide the code to supplement the discussion. Very cool! Itโ€™s not everyday that the struggling PHP beginner comes across a truly well written, easy-to-understand explanation on OOP in PHP, but this one is just the sort of resource that a self-educated PHP Developer (such as myself) can dig into, find a lot of meaningful substance, and take away a great amount of new knowledgeโ€“ if the student developer reads carefully, and actively.
โ€œโ€ฆactive reading?โ€ฆโ€, do you say? What does Active Reading mean? The easiest way for me to explain what I mean by โ€˜read carefully, and activelyโ€™ is to describe specifically, my own approach to active reading.

The Active Reader:

When I really want to learn something, i do my best to approach the material with a clear mind. I would filter as much background noise as possible by turning off the television and radio, and Iโ€™d settle down with the study material and ensure that I have some way of taking notes on the material as I read it. Active reading, in short, is simply reading and writing notes on the material while reading, so the notes represent the readerโ€™s thoughts as the new knowledge is not fully understood, but as it is being assimilated, little by little. My preferred medium for note-taking is the text document. In the past, iโ€™ve been a big fan of MS WordPad (in MS Windows), but Notepad, or Gedit, VIM, etc., would all work as well. I prefer WordPad (when working in a Windows environment) because it is can create Rich Text Format, or RTF documents, where Section Headings can be made to separate, visually, the primary concepts of the material at hand (just as you might use <h1>, <h2>, etc., to separate sections in your HTML documents.

Whatever the text editor Iโ€™ve chosen to use, I always jot down a lot of notes as i make my way through the text. I use my own words, abbreviations, and slangโ€“ not at all concerning myself with any other reader, so I can most efficiently record my thoughts on all of the key concepts. Sometimes, I even write an entire paragraph at the end (or, at the beginning) of each section to summarize what I gleaned from the text, regurgitating in my own words, so i know iโ€™ve learned it enough to repeat it. If Iโ€™m really in hardcore study mode, Iโ€™ll write my own study questions so, supposing I might come back to my notes in a few days, weeks, or even months later, Iโ€™ve got some point of reference for those key concepts, or terms I learned when I first read the article; tutorial; whatever the documentation might have been which was the focus of my notes. In the case of the Classes and PHP article at PHPBuilder.com, my Active Reading study questions included:

  • โ€œWhat is a Class?โ€
  • โ€œWhat is the purpose of a Function relative to a Class?โ€
  • โ€œWhy would we want to use a Constructor?โ€
  • โ€œHow is it made / what makes up an Object?โ€

โ€ฆamong others. Be an active reader: take notes, divide and summarize key concepts in the material, and write your own study questions. Youโ€™ll thank yourself for it later.

Community Learning Support:

To my disappointment, as i was following along w/ the code samples in Classes and PHP, i found that when i tested my code i was getting errors. Being completely unfamiliar with most of the material in the article, i decided to break into CSI mode (as in, Crime Scene Investigators). Thankfully, this scene didnโ€™t require too much investigation because at PHPBuilder.com, a strong, community-driven site, users tend to log in and provide their own commentary on articles such as this. Indeed, there is a bountiful thread of user discussion right under the Classes and PHP article. Learning without the guidance of a Computer Science / PHP / Web Application Development Programming instructor, one will not find a resource for learning which will yield more topical understanding than a medium such as the PHPBuilder.com articles portal. Indeed, tutorial videos, and other step by step educational methods are great for unassisted learning, but thereโ€™s something to be said for the knowledge gained through the process of indulging in a well written articleโ€“ the readerโ€™s need to be proactive in the process (i.e. active reading), to engage in supplemental research from other resources to bolster his or her developing understanding, and to really get in there and hash-out any code examples provided must certainly be at least nearly as effective as any formal training in a classroom filled with a hundred other students, if not even a better study.

What are you waiting for? Go read Classes and PHP, and practice your active reading technique.
Good luck, and enjoy!

Note: if you have difficulty with the URL i provided, then simply search PHPBuilder.com โ€” NOT the forum section, but the root site where the articles areโ€“ and look for โ€œClasses and PHPโ€ by Rod Kreisler

Whatchu do


Leave a Reply

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