Object Oriented Programming with PHP – Lesson 01

Meet you again on Lesson one, Hope you have got a clear picture about Introduction in your mind.

For my today and coming session you have to create two php files :
1. index.php
2. oop.php

OOP is all about creating module based codes. So our object oriented PHP code file also a dedicated php file(oop.php) then we will added to our normal file called index.php

In today’s session all our Object Oriented PHP codes are embedded to oop.php

Creating A Class – classes are the templates, they are used to define an objects
You can define your own class with the keyword class followed by the name you like

1
2
3
4
5
<?php
class workers{

}
?>


Classes are the blue-prints for php objects we will see about more on class later. Classess contain variables and functions these are called properties in OOP.


Now Lets Create a variable into the above class “workers”

1
2
3
4
5
<?php
class workers{
var $name;
}
?>

Now we are going to see how to add add functions to the class “workers”

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
class workers{
var $name;

function set_name($new_name)
{
$this->name = $new_name;
}

function get_name()
{
return $this->name;
}
}
?>

I hope you’re enjoyed this session we will meet you on next session more details on each and every syntax in above code.

Object Oriented Programming with PHP – Introduction

OOP is a kind of approach added in PHP5 that makes building complex, modular and reusable web applications that much easier.

PHP programmers now have the big power of Object Oriented Concepts in PHP on the release of PHP5.



In this tutorial session, we are walk-through step by step approach to understanding the OOP PHP and differences between the old PHP.

People get more confused when programming because they have lack of knowledge in basic concepts.Therefore we going slowly to understanding each and every key points when we dealing with OOP concepts.

For this and coming sessions you should know about basics of PHP shch as functions, variables, conditions, loops and so on.

That’s all about introduction. we will meet in our Lesson 1