Customer Object

<?php
class Customer
{
private $_name;
private $_gender;
private $_details = "Empty";

//Setter Functions
function setName($name)
{
$this->_name = $name;
}
function setGender($gender)
{
$this->_gender = $gender;
}
//Getter Functions
function getName()
{
return($this->_name);
}
function getGender()
{
return($this->_gender);
}
function getDetails()
{
$this->_details = "A " . $this->_gender . " named " . $this->_name;
return($this->_details);
}
}

//Create some objects
$the_customer = new Customer();
$the_second_customer = new Customer();

$the_customer->setName('Timmy');
$the_customer->setGender('Male');

$the_second_customer->setName('Suzanna');
$the_second_customer->setGender('Female');

echo 'Customer 1 = ' . $the_customer->getDetails() . '<br>';
echo 'Customer 2 = ' . $the_second_customer->getDetails() . '<br>';
?>

0 Comments

You must be logged in to post a comment.