Website: Object Oriented Programming In PHP

OOP For Beginners

We can imagine our universe made of different objects like sun, earth, moon etc. Similarly we can imagine our car made of different objects like wheel, steering, gear etc. Same way there is object oriented programming concepts which assume everything as an object and implement a software using different objects.
Object Oriented Concepts:

Before we go in detail, lets define important terms related to Object Oriented Programming.

    Class: This is a programmer-defined datatype, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.

    Object: An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.

    Member Variable: These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.

    Member function: These are the function defined inside a class and are used to access object data.

    Inheritance: When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.

    Parent class: A class that is inherited from by another class. This is also called a base class or super class.

    Child Class: A class that inherits from another class. This is also called a subclass or derived class.

    Polymorphism: This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it make take different number of arguments and can do different task.

    Overloading: a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.

    Data Abstraction: Any representation of data in which the implementation details are hidden (abstracted).

    Encapsulation: refers to a concept where we encapsulate all the data and member functions together to form an object.

    Constructor: refers to a special type of function which will be called automatically whenever there is an object formation from a class.

    Destructors: refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.

Defining PHP Classes:

The general form for defining a new class in PHP is as follows:



Here is the description of each line:

    The special form class, followed by the name of the class that you want to define.

    A set of braces enclosing any number of variable declarations and function definitions.

    Variable declarations start with the special form var, which is followed by a conventional $ variable name; they may also have an initial assignment to a constant value.

    Function definitions look much like standalone PHP functions but are local to the class and will be used to set and access object data.

Share on Google Plus

About Akins Mathew

 Hello! I’m a Programmer and  CEO/Founder of iReporter News Network Int'l [iNNi], a Creative Website Designer/Developer, Mobile App Designer, Business Enthusiast, Writer, Blogger and Musician. Currently obsessed with Mobile App Development.

"A logical person, Psychologically intelligent, and physically thrilling".

Connect with me on Facebook | Twitter | Reverbnation

STAGE NAME: Dr Magic
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Enter here your comment!

Note: Only a member of this blog may post a comment.

-->