<?php
class Employee {
public $lastName;
public $firstName;
function __construct($firstname, $lastname ) {
echo "constructor responded";
$this->firstName = $firstname;
$this->lastName = $lastname;
}
function getFullName() {
return "{$this->firstName}" . " {$this->lastName}";
}
}
class Record {
public $str="";
public function write( $pass ) {
$str .= $pass->getFullName();
echo "received class instance as a parameter <br/>";
echo $str;
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>instance_parameter.php</title>
</head>
<body text="#000080" bgcolor="#FDE6C1">
<form method="POST" action="instance_parameter.php">
<p>Name: <input type="text" name="T1" size="20"><br>
ID
<input type="text" name="T2" size="20"><br>
<input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>
<?php
$pfname = $_POST['T1'];
$plname = $_POST['T2'];
echo "creating an object that will call constructor<br>";
$emp = new Employee( $pfname, $plname);
$writer = new Record();
$writer->write( $emp );
?>
</body>
</html>