Introduction to OOP
OOP stands for Object Oriented Programming
Category: Coding
Views: 5787

Introduction to OOP Introduction to OOP

First things first, OOP stands for Object Oriented Programming.
A class is a group of functions and variables.
Lets create a class.
In the example's below we are going to create a class which will allow us to display what our favourite movie is.
Code:
class yourclass{

}
This is how we name our class and open it.

Now lets create a variable and function.
Code:
class movie{ //name the class
var $movie = 'none';
function movie($moviename){ //name the function
$this->movie = $moviename; //sets the var movie to the value of moviename
}
}
Now we have our function done. This will set the value of $moviename to $movie, next we will create a function to show it.

Code:
class movie{ //name the class
var $movie = 'none';
function movie($moviename){ //name the function
$this->movie = $moviename; //sets the var movie to the value of moviename
}
function showmovie(){ //name the function
return $this->movie; //return the movie var
}
}
This function will show the contents of the $movie variable.

We have still to create the bit that will call our class and then use the functions.

Code:

class movie{ //name the class
var $movie = 'none';
function movie($moviename){ //name the function
$this->movie = $moviename; //sets the var movie to the value of moviename
}
function showmovie(){ //name the function
return $this->movie; //return the movie var
}
}
$mov = new movie;
$mov->movie('Movie name!');
echo $mov->showmovie();
And we are done! You have created you're first class which will spectify your favourite movie and return it.

If you would like more help with this tutorial please register and visit the forum.

About Michael

Michael Dunlop Michael Dunlop personal statement

“But I am already older than 21”, I hear you cry. Don’t worry, despite the name, the information and advice is more geared towards retiring prior to having a fake hip installed.

Website Sponsors
Get Retire at 21's FREE Secrets

Get Retire at 21's FREE Secrets

Find out how I'm going to Retire VERY Early Subscribe for my Free Secrets Privacy Guaranteed. 100% Spam free.

Join The Forum
Recommended Websites
Credit card processing made easy! Same day approvals, no application fee, free setup, 24/7 customer support, free equipment, and more. Cardaccept is the clear choice.
Rotate and track a GIF, JPG, PNG, FLASH and text ads on your website. Sell Advertising and accept payments. Free Trial, No credit card needed.
Create stuning Flash websites at Wix.com, Seo Friendly, Drag & Drop builder.
See how you can do it. Brand new system just went "live." Get in early to change your financial future. Act now, don't delay.
 
Advertise Here
Feature Interviews
Darren Rowse is perhaps the most famous ... Read more
Todays interview is with Rachna Kingston ... Read more
This is an awesome interview. I ... Read more
David is a 20 year old ... Read more
Recommended Resources