<?php class Employee { public $name; public $age; public $job; public $salary; public function work() { echo '働いている!'; } } $saji = new Employee(); // Employeeクラスのインスタンスを生成 $saji->work(); //インスタンスからメソッドを呼び出す
include_once "Entities\\Manager.php"; include_once "Entities\\Department.php"; $ivan = new Person("vano", 111); // $ivan -> id = 111123; // $ivan -> name = "vano"; echo $ivan->getName() . "\n"; echo $ivan->getId() . "\n"; echo $ivan->__get("name") . "\n"; echo $ivan->__get("id") . "\n"; $ivanSalary = $ivan->__get("salary") . "\n"; $ivanAge = $ivan->age . "\n"; // неявно вызывает функцию __get echo "ivan has salary :" . $ivanSalary; echo "ivan has age :" . $ivanAge; $he = new Employee(); $hisResult = $he->work(true); echo "Он работал весь день и результат: " . $hisResult . "\n"; $she = new Manager(10000000); $herSalary = $she->salary; echo "Она не работала весь день и ее зарплата: " . $herSalary . "\n"; $employees = array(); $department = new Department("IT", $employees, $she); $she->hire($ivan); $allEmployees = $department->getEmployees(); printAllEmployees($allEmployees); $she->hire($he); $allEmployees = $department->getEmployees(); printAllEmployees($allEmployees); $she->fire($he); $allEmployees = $department->getEmployees(); printAllEmployees($allEmployees);
<?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';
$t9 = new Task("Task 9", 3); $t10 = new Task("Task 10", 2); $t11 = new Task("Task 11", 2); $t12 = new Task("Task 12", 2); $allWork = new AllWork(); $allWork->addTask($t1); $allWork->addTask($t2); $allWork->addTask($t3); $allWork->addTask($t4); $allWork->addTask($t5); $allWork->addTask($t6); $allWork->addTask($t7); $allWork->addTask($t8); $allWork->addTask($t9); $allWork->addTask($t10); $allWork->addTask($t11); $allWork->addTask($t12); $e1 = new Employee("Ivan", $allWork); $e2 = new Employee("Niki", $allWork); $e3 = new Employee("Tina", $allWork); $moreWork1 = false; $moreWork2 = false; $moreWork3 = false; $days = 1; while (!$moreWork1 || !$moreWork2 || !$moreWork3) { echo 'Start working day number ' . $days . PHP_EOL; $days++; $moreWork1 = $e1->work(); $moreWork2 = $e2->work(); $moreWork3 = $e3->work(); }