fork download
  1. <?php
  2.  
  3. include('classes.php');
  4.  
  5. /**
  6.  * essential class Department's declaration in classes.php:
  7.  * class Department {
  8.  * protected string $name;
  9.  * protected array $staff;
  10.  *
  11.  * public function __construct($name) {
  12.  * $this->name = $name;
  13.  * }
  14.  *
  15.  * public function addToStaff($employee) {
  16.  * $this->staff[] = $employee;
  17.  * }
  18.  * }
  19.  */
  20.  
  21. $input = [
  22. 'Purchasing' => [
  23. [9, Employee::MANAGER, 1],
  24. [3, Employee::MANAGER, 2],
  25. [2, Employee::MANAGER, 3],
  26. [2, Employee::MARKETER, 1],
  27. [1, Employee::MANAGER, 2, true]
  28. ],
  29.  
  30. 'Sales' => [
  31. [12, Employee::MANAGER, 1],
  32. [6, Employee::MARKETER, 1],
  33. [3, Employee::ANALYST, 1],
  34. [2, Employee::ANALYST, 2],
  35. [1, Employee::MARKETER, 2, true]
  36. ],
  37.  
  38.  
  39. 'Advertising' => [
  40. [15, Employee::MARKETER, 1],
  41. [10, Employee::MARKETER, 2],
  42. [8, Employee::MANAGER, 1],
  43. [2, Employee::ENGINEER, 1],
  44. [1, Employee::MARKETER, 3, true]
  45. ],
  46.  
  47.  
  48. 'Logistics' => [
  49. [13, Employee::MANAGER, 1],
  50. [5, Employee::MANAGER, 2],
  51. [5, Employee::ENGINEER, 1],
  52. [1, Employee::MANAGER, 1, true]
  53. ]
  54.  
  55. ];
  56.  
  57. $depts = [];
  58.  
  59. foreach ($input as $dept => $staff) {
  60. $currentDept = new Department($dept);
  61. foreach ($staff as $employeeGroup) {
  62. $quantity = $employeeGroup[0];
  63. $type = $employeeGroup[1];
  64. $grade = $employeeGroup[2];
  65. $chief = isset($employeeGroup[3]) ? true : false;
  66. for ($c = 0; $c < $quantity; $c++) {
  67. $employeeObject = new $type($grade, $chief);
  68. $currentDept->addToStaff($employeeObject);
  69. }
  70. }
  71. $depts[] = $currentDept;
  72. }
Runtime error #stdin #stdout #stderr 0.02s 24720KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Warning:  include(classes.php): failed to open stream: No such file or directory in /home/rdKN7J/prog.php on line 3
PHP Warning:  include(): Failed opening 'classes.php' for inclusion (include_path='.:/usr/share/php') in /home/rdKN7J/prog.php on line 3
PHP Fatal error:  Uncaught Error: Class 'Employee' not found in /home/rdKN7J/prog.php:23
Stack trace:
#0 {main}
  thrown in /home/rdKN7J/prog.php on line 23