Why PHP and Javascript Object Oriented Programming (OOP) are Easier

I use the CodeIgniter and MooTools frameworks for my website projects nowadays. They are far easier to work with and understand if you understand Object Oriented Programming. If you are spaghetti coding your websites line by line, you will be in for a treat when you learn OOP. Here is how it works:

Say you want to describe a human being with code. You will create a class called Human:

class Human {

}

Now, you want the human to perform a few functions. This is simple also; you create functions within the class to describe the human’s actions.

class Human {

function Eat($food) {

}

function Sleep($time) {

}

}

Now our human can eat and sleep. In PHP, you would create a new human by instantiation. So we can create Bob.

$Bob = new Human();

If we want Bob to eat,

$Bob->Eat($chicken);

Go to sleep, Bob!

$Bob->Sleep($one_hour);

We have just told Bob to eat chicken and sleep for an hour. Pretty easy, eh?

This same principal applies to CodeIgniter for PHP and MooTools for Javascript. They are object oriented, so it is very easy to implement them into youur websites. If you need session handling to password protect certain pages of your website, you just instantiate the session library in CodeIgniter and it will manage user sessions for you. If you need to update a layer on your website dynamically, such filling in the current weather or water temperature (such as this site: www.easylakeliving.com) you can do so simply by calling:

new Ajax('url_to_get_weather', {
method: 'get',
update: $('current_weather')
}).request();

Just by calling Ajax, you are updating the ‘current_weather’ layer on the website with the information provided by the URL ‘url_to_get_weather.’

That’s OOP for ya!



2 Responses to “Why PHP and Javascript Object Oriented Programming (OOP) are Easier”

  1. I had to read this post twice, because it was interesting. I read some of your other posts you do make some good points

  2. Barbara says:

    hi your article is very interesting friend liked me a lot of published information we go ahead with your pots
    than you :)
    ________________________________________________
    I love Internet :)

Leave a Reply