6. Object datatype
Objects are Compound data types.
An Object can hold a collection of datatypes. We can create our own datatypes using Object datatype
is_object() function is used to test whether a variable is an object instance.
Example :
<?php
class MyDetails {
private $name;
private $age;
private $message;
function getName() {
echo "Name : ".$this->name ."<br/>";
}
function setName($name) {
$this->name = $name;
}
function getAge() {
echo "Age : ".$this->age ."<br/>";
}
function setAge($age) {
$this->age = $age;
}
function setMessage($message) {
$this->message = $message;
}
function getMessage() {
echo "Message : ".$this->message ."<br/>";
}
}
//Object Datatype
$myDetails = new MyDetails;
//Calling Setter Functions
$myDetails->setMessage("I love PHP!");
$myDetails->setAge("19");
$myDetails->setName("Mike");
//Calling Getter Functions
$myDetails->getName();
$myDetails->getAge();
$myDetails->getMessage();
?>
Output
Name : Mike
Age : 19
Message : I love PHP!
Note :
Objects is an Advance topic, it is covered in details after learning Functions.