OOP's


  • OOP's stands for Object Oriented Programming System.

  • PHP is not an object-oriented language because OOP wasn't added until PHP 3.

  • When PHP 5 was released in July 2004,the path of classes and objects work in PHP was changed originally.

  • PHP 4 objects are disability with those designed for PHP 5.

  • PHP 6 handles objects is same to PHP 5.

  • Object Oriented Programming(OOP) is technique to design your application.

  • You can create Modular Web Application with the help of OOP.


Benefits of OOP


  • Reusability : An object is an entity which has collection of properties and methods which can interact with other objects.

  • Refactoring :OOP provide the maximum benefit because all objects are small entities and contain its properties and methods as a part of itself.

  • Maintenance :Object Oriented code is easier to maintain because it follows coding strict conventions .

  • Efficiency :Object Oriented programming is developed for better efficiency and ease of development process.Some design patterns are developed to create better and efficient code.

Class


  • A class is simply a representation of a type of object.

  • It is the blueprint/ plan/ template that describe the details of an object.

  • Class is known as fundamental building block of all object-oriented code.

  • A variable associated with a class is referred to as a property,and a function is called a method.

  • It is collection of related variables and functions, all wrapped up in a pair of curly braces and labeled with the name of the class.

Syntax :
class
{
   //properties defined here.
   //methods defined here.  
}
			 
Example :

<?php 
class First
{
function add()
{
$var1=10;
$var2=20;
$var=$var1+$var2;
echo "$var";	
}
}
?>

Object


  • An Object is a real world entity.

  • An object can be considered a "thing" that can perform a set of related activities.

  • you want to create an instance(object) of the class by using the new keyword like this:

$obj = new First();

Example :
<?php 
class First
 {
  function add() 
   { 
    $var1=10; 
    $var2=20;
    $var=$var1+$var2; 
    echo "$var"; 
   } 
 } 
$obj=new First();//creates an object called $obj
$obj->add();
?>
Output :
30