PHP Object

Rumman Ansari   Software Engineer   2020-02-06   5440 Share
☰ Table of Contents

Table of Content:


An object is a data type that stores data and information on how to process that data.

In PHP, an object must be explicitly declared.

First, we must declare a class of objects. For this, we use the class keyword. A class is a structure that can contain properties and methods:

Example Code:



<?php
class Car {
    function Car() {
        $this->model = "Model Z.10";
    }
}

// create an object
$carObj = new Car();

// show object properties
echo $carObj->model;
?>


Output:

The above code will produce the following result-


Model Z.10