What is an object in PHP

Basic understanding about PHP object

 

Before entering into the depth of PHP Object Oriented Programmingconcept at first we need to understand what is an object in PHP. The object is nothing but it’s a real world entity. For example, a human, your dog, your bicycle, your desk everything are real world object. Every object has two attributes state and behavior. A human has many state and behavior such as

  • Human state: hands, legs, mouth etc.
  • Human behavior: moving hands, walking leg etc.

You can hone your skill by identifying real world objects with state and behavior. Think about your table lamp. It has two state off and on and has two behavior turning off and turning on.

In PHP object oriented programming we use state as a variable and behavior as a method. Object oriented method is actually a PHP function and within function we use variable that is actually object state. A method perform specific works by combining it's internal state.Using methods we hide internal state from the outside world is known as data encapsulation…. that is the foundation of PHP object oriented programming.  Binding object into methods give us huge benefits such as modularity, information hiding, securing data, code re-use etc. So we think every real world entity is an object and that object perform a specific task.

 

Every real world entity is an Object 

 

In PHP coding you need to think everything as an object. Remember that every real world entity is a PHP object. Entity and instance is a relative word. So don't confuse with those world. For example, such that we want to create a blog using PHP with object oriented programming. So you need to think the blog is an object. To be a PHP object oriented programmer you need to think everything as an object.  

Traditional PHP programming language doesn't perform well. If we launch a software using traditional PHP and after launch if we want to extend functionality, re-use the code and hide software source code from hackers…….actually it is very tough for us without the help of PHP object oriented programming. So now it’s time to enter PHP object oriented programming world.

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP