function addEmployee(Employee $e) { $this->_employees[] = $e; echo "<p>{$e->getName()} has been added to the {$this->_name} department.</p>"; }
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employees</title> </head> <body> <h3>Employees</h3> <?php include './Employee.php'; include './Manager.php'; $emp1 = new Employee(); $emp1->setName("Raynald"); echo "{$emp1->getName()}"; // $emp1->name = "Pancho"; // Causes error $manager = new Manager(); $manager->setName('raynaldmo'); echo "{$manager->getName()}"; ?> </body> </html>
} function setPhone($phone) { $this->phone = $phone; } function getPhone() { return $this->phone; } function printPersonInfo() { echo "<hr><b>Employee Info</b><br>"; echo $this->name . "<br>\n"; echo $this->address . "<br>\n"; echo $this->phone . "<br>\n"; } } // Create objects of the class $Heidi = new Employee(); $Heidi->setName("Heidi Clum"); $Heidi->setAddress("1234 Somewhere Blvd "); $Heidi->setPhone("123-456-7890"); echo $Heidi->getName() . "<br>\n"; echo $Heidi->getAddress() . "<br>\n"; echo $Heidi->getPhone() . "<br>\n"; $Brad = new Employee(); $Brad->setName("Brad Bit"); $Brad->setAddress("4321 Sunset Blvd "); $Brad->setPhone("987-654-3210"); $Heidi->printPersonInfo(); $Brad->printPersonInfo();
<?php require_once 'Person-class.php'; require_once 'Employee-class.php'; $werknemer = new Employee('Ryan', 'Carsonified'); // Instantie aanmaken van de klasse Employee // Aangepaste employee klasse //$werknemer = new Employee('Ryan', 'Carsonified'); // Instantie aanmaken van de klasse Employee $dialog; $dialog[] = 'De werknemer ' . $werknemer->getName() . ' werkt bij ' . $werknemer->getCompany() . ' en heeft ' . $werknemer->getSavings() . '€ op zijn spaarboekje staan.'; $dialog[] = $werknemer->work(8); $dialog[] = 'De werknemer ' . $werknemer->getName() . ' heeft ' . $werknemer->getSavings() . '€ op zijn spaarboekje staan.'; // Method uit de parent class require_once 'voorbeeld-classes-inheritance-parent-view.php';
/** * Used to add composite members to the class * Uses type hinting to expect an Employee obj which is then added to the internal array * @param Employee $e */ function add(Employee $e) { $this->_employees[] = $e; echo "<p><strong>{$e->getName()}</strong> has been added to the team <strong>{$this->getName()}</strong>.</p>"; }
{ public $name; public $age; public $job; public $salary; public function __construct() { $this->name = "名無しさん"; $this->age = 0; $this->job = "研修員"; $this->salary = 300; } public function work() { echo '働いている!'; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } } $saji = new Employee(); echo $saji->getName() . "<BR>"; //名無しさん $saji->setName("佐治"); echo $saji->getName() . "<BR>"; //佐治
<?php class Test { public $name; public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } } class Employee extends Test { public function __toString() { echo $this->name; } } $me1 = new Employee(); $me1->setName('Joshua'); echo $me1->getName();
function add(Employee $e) { $this->_employees[] = $e; echo "<p>{$e->getName()} has been added to team {$this->getName()}.</p>"; }
private $first_name; private $last_name; private $age; private $job; private $salary; public function __construct() { $this->last_name = "名無し"; $this->first_name = "さん"; $this->age = 0; $this->job = "研修員"; $this->salary = 300; } public function work() { echo '働いている!'; } public function getName() { return $this->last_name . " " . $this->first_name; } public function setName($last_name, $first_name) { $this->last_name = $last_name; $this->first_name = $first_name; } } $saji = new Employee(); $saji->setName("佐治", "和弘"); echo $saji->getName(); //佐治 和弘