3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(-1); abstract class AbstractWorker{ public $rank; public $isBoss; public $count; public $coffeeConsumption; public $salary; public $printedPages; public function __construct($count, $rank, $isBoss) { $this->rank = $rank; $this->count = $count; $this->isBoss = $isBoss; } function CalculationOfInformation($rank, $isBoss){ if ($this->rank == 2){ $this->salary = $this->salary * 1.25 * $this->count; } elseif ($this->rank == 3){ $this->salary = $this->salary * 1.5 * $this->count; } else { $this->salary = $this->salary * $this->count; } $this->coffeeConsumption = $this->coffeeConsumption * $this->count; $this->printedPages = $this->printedPages * $this->count; if ($this->isBoss == 1){ $this->salary *= 1.5; $this->coffeeConsumption *= 2; $this->printedPages = 0; } } public function print($value){ return $value; } } class Manager extends AbstractWorker{ public $coffeeConsumption = 20; public $salary = 500; public $printedPages = 200; } class Marketer extends AbstractWorker{ public $coffeeConsumption = 15; public $salary = 400; public $printedPages = 150; } class Engineer extends AbstractWorker{ public $coffeeConsumption = 5; public $salary = 200; public $printedPages = 50; } class Analyst extends AbstractWorker{ public $coffeeConsumption = 50; public $salary = 800; public $printedPages = 5; } class Department { public $name; public $workers = array(); public function __construct($name) { $this->name = $name; } public function addWorkers(AbstractWorker $worker){ $worker->CalculationOfInformation($worker->rank, $worker->isBoss); $this->workers[] = $worker; } public function getInformation(){ $information = array( "name" => 0, "count" => 0, "coffee" => 0, "salary" => 0, "pages" => 0, "salaryDivedePagas" => 0 ); foreach ($this->workers as $worker) { $information["count"] += $worker->print($worker->count); $information["coffee"] += $worker->print($worker->coffeeConsumption); $information["salary"] += $worker->print($worker->salary); $information["pages"] += $worker->print($worker->printedPages); } $information["name"] = $this->name; $information["salaryDividePages"] = $information["salary"] / $information["pages"]; return $information; } } class Company { public $departments = array(); public $col = array(30, 8, 30, 8, 8, 15); public function addDepartment(Department $name){ $this->departments[] = $name; } public function padRight($string, $length){ echo $string; echo str_repeat(" ", $length - mb_strlen($string)); } public function printString(array $array, array $col){ echo $this->padRight($array[0], $this->col[0]) . $this->padRight($array[1], $this->col[1]) . $this->padRight($array[2], $this->col[2]). $this->padRight($array[3], $this->col[3]) . $this->padRight($array[4], $this->col[4]) . $this->padRight($array[5], $this->col[5]); echo "\n\n"; } public function printColumnName(){ $columnName = array("Департамент", "сотр.", "тург", "кофе", "cтр.", "тугр./стр."); // echo $this->padRight("Департамент", $this->col[0]) . // $this->padRight("сотр.", $this->col[1]) . // $this->padRight("тург.", $this->col[2]). // $this->padRight("кофе", $this->col[3]) . // $this->padRight("стр.", $this->col[4]) . // $this->padRight("тугр./стр.", $this->col[5]); // echo "\n\n"; printString($columnName, $this->col); } public function printDepartment(){ foreach ($this->departments as $department) { $information = $department->getInformation(); echo $this->padRight($information["name"], $this->col[0]). $this->padRight($information["count"], $this->col[1]). $this->padRight($information["coffee"], $this->col[2]). $this->padRight($information["salary"], $this->col[3]). $this->padRight($information["pages"], $this->col[4]). $this->padRight($information["salaryDividePages"], $this->col[5]); echo "\n"; } echo "\n"; } public function printTotalValue(){ $totalCoffee = 0; $totalWorkers = 0; $totalSalary = 0; $totalPages = 0; $totalSalaryDivedePages = 0; $totalValue = array(); foreach ($this->departments as $department) { $totalValues = $department->getInformation(); $totalCoffee += $totalValues["coffee"]; $totalWorkers += $totalValues["count"]; $totalSalary += $totalValues["salary"]; $totalPages += $totalValues["pages"]; $totalSalaryDivedePages += $totalValues["salaryDividePages"]; } echo $this->padRight("Всего", $this->col[0]). $this->padRight($totalWorkers, $this->col[1]). $this->padRight($totalSalary, $this->col[2]). $this->padRight($totalCoffee, $this->col[3]). $this->padRight($totalPages, $this->col[4]). $this->padRight($totalSalaryDivedePages, $this->col[5]); echo "\n"; } public function printAverageValue(){ $averageCoffee = 0; $averageWorkers = 0; $averageSalary = 0; $averagePages = 0; $averageSalaryDivedePages = 0; $averageValue = array(); foreach ($this->departments as $department) { $averageValues = $department->getInformation(); $averageCoffee += $averageValues["coffee"]; $averageWorkers += $averageValues["count"]; $averageSalary += $averageValues["salary"]; $averagePages += $averageValues["pages"]; $averageSalaryDivedePages += $averageValues["salaryDividePages"]; } $averageCoffee /= count($this->departments); $averageSalary /= count($this->departments); $averageWorkers /= count($this->departments); $averagePages /= count($this->departments); $averageSalaryDivedePages /= count($this->departments); echo $this->padRight("Среднее", $this->col[0]). $this->padRight($averageWorkers, $this->col[1]). $this->padRight($averageSalary, $this->col[2]). $this->padRight($averageCoffee, $this->col[3]). $this->padRight($averagePages, $this->col[4]). $this->padRight($averageSalaryDivedePages, $this->col[5]); } } $vektor = new Company; $procurementDepartment = new Department("Закупок"); $procurementDepartment->addWorkers(new Manager(9, 1, 0)); $procurementDepartment->addWorkers(new Manager(3, 2, 0)); $procurementDepartment->addWorkers(new Manager(2, 3, 0)); $procurementDepartment->addWorkers(new Marketer(2, 1, 0)); $procurementDepartment->addWorkers(new Manager(1, 2, 1)); $sellingDepartment = new Department("Продаж"); $sellingDepartment->addWorkers(new Manager(12, 1, 0)); $sellingDepartment->addWorkers(new Marketer(6, 1, 0)); $sellingDepartment->addWorkers(new Analyst(3, 1, 0)); $sellingDepartment->addWorkers(new Analyst(2, 2, 0)); $sellingDepartment->addWorkers(new Marketer(1, 2, 1)); $advertisingDepartment = new Department("Рекламы"); $advertisingDepartment->addWorkers(new Marketer(15, 1, 0)); $advertisingDepartment->addWorkers(new Marketer(10, 2, 0)); $advertisingDepartment->addWorkers(new Manager(8, 1, 0)); $advertisingDepartment->addWorkers(new Engineer(2, 1, 0)); $advertisingDepartment->addWorkers(new Marketer(1, 3, 1)); $logisticsDepartment = new Department("Логистики"); $logisticsDepartment->addWorkers(new Manager(13, 1, 0)); $logisticsDepartment->addWorkers(new Manager(5, 2, 0)); $logisticsDepartment->addWorkers(new Engineer(5, 1, 0)); $logisticsDepartment->addWorkers(new Manager(1, 1, 1)); $vektor->addDepartment($procurementDepartment); $vektor->addDepartment($sellingDepartment); $vektor->addDepartment($advertisingDepartment); $vektor->addDepartment($logisticsDepartment); $vektor->printColumnName(); $vektor->printDepartment(); $vektor->printTotalValue(); $vektor->printAverageValue();
based on CCVm3
Output for 7.0.0 - 7.2.6
Fatal error: Uncaught Error: Call to undefined function printString() in /in/caam4:144 Stack trace: #0 /in/caam4(260): Company->printColumnName() #1 {main} thrown in /in/caam4 on line 144
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: Call to undefined function printString() in /in/caam4:-1 Stack trace: #0 /in/caam4(-1): Company->printColumnName() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: Call to undefined function printString() in /in/caam4:144 Stack trace: #0 /in/caam4(260): Company->printColumnName() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'print' (T_PRINT), expecting identifier (T_STRING) in /in/caam4 on line 38
Process exited with code 255.