Home > OOP > PHP Programmer Introduction to OOP Programming & Creating an Object.

PHP Programmer Introduction to OOP Programming & Creating an Object.

November 13th, 2008

In this tutorial I will explain how to start OOP properly and how to polish your skills as a PHP Programmer.

Object-Oriented Programming (OOP) tutorials can be filled with programming theory and big words such as inheritance, encapsulation and abstraction. You will see that many will explain code by comparing their samples to toasters and car radios, which should help confuse the reader some.

Once you take away all the big words and chest bumping that comes with OOP, you will find it interesting and very helpful. As the years move along you will understand why…

I don’t want this to be another cookie-cutter tutorial that only serves to confuse you.
It is this PHP Programmer’s intention to explore OOP with you in a way that will help you sharpen your skills as a PHP Developer. As I mentioned, over the years you will build a foundation that is strong and helpful to yourself and others.

I want you to imagine a box. This box can be any type of box: Cardboard, Wood, Plastic,Rubber, Small, Large…

Next, imagine that you placed something inside this box: a pebble, a book, a box of matches…

Wouldn’t it be neat to touch the box and then it tells us what is inside of it? Actually, with OOP it is possible!!

$aBox = new Box(”Alex”);
echo $aBox->click_box();

The variable $aBox is equal to our new magical Box(). What is known to PHP Programmer’s in OOP as an object.

Now that we have an active variable($aBox) representing the Box(), we want to put Alex in the box. When we want to “click” the button to tell us whats inside of this box, we will ask using a get_whats_inside function to $abox.

As you figured, we cannot run this code yet. We havent given any directions as to what the click button is supposed to do. You will find this in our next section on classes.

Next Section - Classes

OOP

  1. November 19th, 2008 at 21:18 | #1

    I like the introductory articulation of OOP. However,
    I basically disagree with the following statement;

    “You will see that many will explain code by comparing their samples to toasters and car radios, which should help confuse the reader some.”

    Most people who do not have pre-existing knowledge need comparison and contrast using a familiar experience. The building of intellect and understanding often requires the analogy building block.

    I enjoyed this web experience. Thank you

  2. Alex
    November 20th, 2008 at 00:42 | #2

    I am glad you liked the website. What I meant to imply was that over the internet its common to lose oneself within the reader’s perception of an object. Rather than use the simplest form of a box, many tutorials use more complex scenarios/objects to symbolize something as simple as a box. I do agree with you as far as needing to give some sort of illustration to represent what the tutorial is trying to explain. That is why I chose the box.

    I hope you stick around as I will be adding more posts over the next couple of weeks. These will still be geared toward helping the new PHP Programmers get a good start at PHP.

    Thank you again for your comment!

  3. Philips Tel
    January 26th, 2009 at 05:22 | #3

    great tut!!

  4. March 10th, 2009 at 20:28 | #4

    Thanks!! :)

  1. December 1st, 2008 at 20:01 | #1