Creating PHP Object

Many novice programmers want to know what it is OOP?

Well… OOP stands for Object Oriented Programming. And now another question, what does it mean by Object Oriented Programming?

Hm… Let’s start with an example about an object.

Let’s take the example of a car. A car is an object. Isn’t it? Yeah, a normal car generally has a engine, wheels, doors, steering wheel and color. When we make a car park, we will arrange a lot of cars in it. If we create a car with OOP in programming concepts, we will organize them easily. We just need to put a car and calling the property of a car. First car will look like a normally car. Second car without a wheels, third car without windows and so on.

Now, let’s jump into code:

<?php
class Car
{ 
    function Doors($numCar, $count)
    {
        echo "Car Number: ".$numCar." has ".$count." dor(s)<br>";
 
            function Color($numCar, $color)
            {
                echo " Car Number: ".$numCar." doors color are ".$color."<br>";
            }
    }
 
    function Wheels($numCar)
    {
        echo " Car Number: ".$numCar." has 4 wheels<br>";
    }
}
$car01 = new Car;
$car01->Doors(1,25);
$car01->Wheels(1);

echo "<br>";
$car02 = new Car;
$car02->Doors.Color(2,'red');
$car02->Wheels(2);
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s