<?php
class Person
{
private $_name;
private $_age;
function __construct($name, $age = 0)
{
if (!is_int($age))
{
throw new Exception("Cannot assign non integer value to
integer field, \'Age\'");
}
$this->_age = $age;
$this->_name = $name;
}
public function setAge($age)
{
if (!is_int($age))
{
throw new Exception("Cannot assign non integer value to
integer field, \'Age\'");
}
$this->_age = $age;
}
public function yearsToRetire()
{
return 67 - $this->_age;
}
}
$person = new Person("Wes");
$person->setAge(31);
echo $person->yearsToRetire();
?>