Sunday, December 16, 2012

OOP In PHP

Object Oriented Programming  is a paradigm which is nowadays the most popular way to develop any application and most of the modern day language is based on this paradigm.

OOP or Object Oriented Programming PHP has so many features like:
Class
Object
Polymorphism
Dynamic Binding...etc.

PHP Class Object:
In object oriented programming a class can be an abstract data type, blue print or template. You could consider the name of a class as noun like name of a person, place or thing. For example Fruit is a class, where apple, orange are the object of this class.
PHP Class Object:
In object oriented programming a class can be an abstract data type, blue print or template. You could consider the name of a class as noun like name of a person, place or thing. For example Fruit is a class, where apple, orange are the object of this class.
Object is the instantiate of a class. A class consists of a member variable and methods. In PHP we need to declare the access specifiers (public, private, or protected) separately for
PHP Object Class Example:
<?php
class A
{
public function disp(){
echo "Inside the class<br/>";
}}
$a=new A();
$a->disp();
A::disp();
?>
Output:
Inside the class
Inside the class

Explanation:

In the above programming we create a class named A, it has a publically declared function disp(), on the outer side of the class we instantiate the object $a, we call the function disp with -> operator. Any class can access it's member using :: operator.

No comments:

Post a Comment