3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); abstract class AbstractWorker{ private $rank; private $isBoss; private $coffee; private $salary; public $pages; public function __construct( $rank, $isBoss) { $this->rank = $rank; $this->isBoss = $isBoss; } public function getSalary(){ $salary = $this->salary; if ($this->rank == 2){ $salary = $this->salary * 1.25; } elseif ($this->rank == 3){ $salary = $this->salary * 1.5; } return $salary; } public function getCoffee(){ $coffee = $this->coffee; if ($this->isBoss == 1){ $coffee = $this->coffee * 2; } return $coffee; } public function getPages(){ $pages = $this->pages; // if ($this->isBoss == 1){ // $pages = $this->pages * 0; // } return $pages; } } class Manager extends AbstractWorker{ public $coffee = 20; public $salary = 500; public $pages = 200; } class Marketer extends AbstractWorker{ public $coffee = 15; public $salary = 400; public $pages = 150; } class Engineer extends AbstractWorker{ public $coffee = 5; public $salary = 200; public $pages = 50; } class Analyst extends AbstractWorker{ public $coffee = 50; public $salary = 800; public $pages = 5; } class Department{ public $name; public $workers = array(); public function __construct($name) { $this->name = $name; } public function addWorker(AbstractWorker $worker){ $this->workers[] = $worker; } public function getNumberWorkers(){ return count($this->workers); } public function getDepartmentSalary(){ $totalSalary = 0; foreach ($this->workers as $worker) { $totalSalary += $worker->getSalary(); } return $totalSalary; } public function getDepartmentCoffee(){ $totalCoffee = 0; foreach ($this->workers as $worker) { $totalCoffee += $worker->getCoffee(); } return $totalCoffee; } public function getDepartmentPages(){ $totalPages = 0; foreach ($this->workers as $worker) { $totalPages += $worker->getPages(); } return $totalPages; } // public function getWorkers(){ // return $this->workers; // } public function getDepartmentName(){ return $this->name; } public function addWorkersToDepartment(string $profession, int $count, int $rang, int $isBoss){ if ($profession == "Manager"){ for ($i = 0; $i < $count; $i++){ //$this->addWorker(Manager $worker($rang, $isBoss)); $this->addWorker(new Manager($rang, $isBoss)); } } elseif ($profession == "Marketer"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Marketer($rang, $isBoss)); } } elseif ($profession == "Engineer"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Engineer ($rang, $isBoss)); } } elseif ($profession == "Analyst"){ for ($i = 0; $i < $count; $i++){ $this->addWorker(new Engineer ($rang, $isBoss)); } } } } class Company{ public $departments = array(); public function addDepartment(Department $department){ $this->departments[] = $department; } public function getDepartments(){ return $this->departments; } public function getDepartmentCount(){ return count($this->departments); } } class Tabel{ private function padLeft($value, $columnLength){ echo $value; echo str_repeat(" ", $columnLength - mb_strlen($value)); } private function calculatiotOfOutput(array $informarion){ $col1 = 15; $col2 = 10; $col3 = 10; $col4 = 8; $col5 = 8; $col6 = 15; echo $this->padLeft($informarion["name"], $col1) . $this->padLeft($informarion["count"], $col2) . $this->padLeft($informarion["salary"], $col3) . $this->padLeft($informarion["coffee"], $col4) . $this->padLeft($informarion["pages"], $col5) . $this->padLeft($informarion["salaryDividePages"], $col6) . "\n"; } public function printTabel(Company $company){ $columnName = array("name" => "Департамент", "count" => "сотр.", "salary" => "тугр.", "coffee" => "кофе", "pages" => "стр.", "salaryDividePages" => "тугр./стр."); $this->calculatiotOfOutput($columnName); $information = array("name" => "", "count" => 0, "salary" => 0, "coffee" => 0, "pages" => 0, "salaryDividePages" => 0); foreach ($company->getDepartments() as $department) { $information["name"] = $department->getDepartmentName(); $information["count"] = $department->getNumberWorkers(); $information["salary"] = $department->getDepartmentSalary(); $information["coffee"] = $department->getDepartmentCoffee(); $information["pages"] = $department->getDepartmentPages(); $information["salaryDividePages"] = round($department->getDepartmentSalary() / 2, 1); $this->calculatiotOfOutput($information); } echo "\n"; $totalInformation = array("name" => "Всего", "count" => 0, "salary" => 0, "coffee" => 0, "pages" => 0, "salaryDividePages" => 0); $totalInformation["name"] = "Всего"; foreach ($company->getDepartments() as $department) { $totalInformation["count"] += $department->getNumberWorkers(); $totalInformation["salary"] += $department->getDepartmentSalary(); $totalInformation["coffee"] += $department->getDepartmentCoffee(); $totalInformation["pages"] += $department->getDepartmentPages(); } $totalInformarion["salaryDividePages"] = round($totalInformation["salary"] / $totalInformation["pages"], 1); $this->calculatiotOfOutput($totalInformation); $averageInformation = array("name" => "Среднее", "count" => $totalInformation["count"] / $company->getDepartmentCount(), "salary" => $totalInformation["salary"] / $company->getDepartmentCount(), "coffee" => $totalInformation["coffee"] / $company->getDepartmentCount(), "pages" => $totalInformation["pages"] / $company->getDepartmentCount(), "salaryDividePages" => $totalInformation["salaryDividePages"] / $company->getDepartmentCount()); $this->calculatiotOfOutput($averageInformation); } } $vektor = new Company; $zakupki = new Department("Запуки"); $zakupki->addWorkersToDepartment("Manager", 5, 2, 0); $vektor->addDepartment($zakupki); $tabel = new Tabel; $tabel->printTabel($vektor);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0140.00718.43
8.3.50.0110.00418.03
8.3.40.0060.00918.98
8.3.30.0090.00618.79
8.3.20.0040.00420.43
8.3.10.0050.00323.61
8.3.00.0050.00323.65
8.2.180.0120.00316.38
8.2.170.0000.01822.96
8.2.160.0110.00419.39
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0080.00022.25
8.2.120.0040.00426.35
8.2.110.0100.01322.30
8.2.100.0110.00019.19
8.2.90.0060.00319.17
8.2.80.0090.00018.05
8.2.70.0060.00617.36
8.2.60.0080.00018.04
8.2.50.0000.00818.10
8.2.40.0000.01020.52
8.2.30.0030.00620.95
8.2.20.0080.00018.07
8.2.10.0040.00418.12
8.2.00.0040.00418.12
8.1.280.0090.00625.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0100.00028.09
8.1.240.0050.00522.51
8.1.230.0000.01219.33
8.1.220.0040.00417.91
8.1.210.0050.00318.77
8.1.200.0030.00717.60
8.1.190.0040.00417.47
8.1.180.0080.00018.10
8.1.170.0040.00419.09
8.1.160.0040.00419.04
8.1.150.0040.00420.72
8.1.140.0040.00417.86
8.1.130.0000.00718.93
8.1.120.0000.00717.64
8.1.110.0030.00517.49
8.1.100.0040.00417.50
8.1.90.0000.00717.41
8.1.80.0040.00417.49
8.1.70.0020.00517.42
8.1.60.0040.00417.71
8.1.50.0040.00417.64
8.1.40.0040.00417.51
8.1.30.0000.00817.77
8.1.20.0020.01017.77
8.1.10.0080.00017.64
8.1.00.0000.00817.59
8.0.300.0100.00019.82
8.0.290.0050.00316.63
8.0.280.0050.00218.62
8.0.270.0000.00717.39
8.0.260.0000.00720.64
8.0.250.0040.00417.13
8.0.240.0070.00017.04
8.0.230.0000.00717.18
8.0.220.0050.00317.00
8.0.210.0030.00316.97
8.0.200.0000.00717.19
8.0.190.0000.00917.23
8.0.180.0050.00316.95
8.0.170.0050.00317.10
8.0.160.0040.00416.96
8.0.150.0000.00717.08
8.0.140.0040.00417.04
8.0.130.0030.00313.56
8.0.120.0000.00817.00
8.0.110.0000.00817.05
8.0.100.0020.00516.98
8.0.90.0040.00417.13
8.0.80.0130.00317.10
8.0.70.0040.00417.06
8.0.60.0020.00517.07
8.0.50.0040.00416.97
8.0.30.0090.01117.17
8.0.20.0100.01017.40
8.0.10.0040.00417.19
8.0.00.0060.01316.80
7.4.330.0050.00016.84
7.4.320.0000.00616.61
7.4.300.0070.00016.64
7.4.290.0030.00316.53
7.4.280.0080.00016.48
7.4.270.0050.00216.48
7.4.260.0040.00416.60
7.4.250.0040.00416.64
7.4.240.0040.00416.60
7.4.230.0080.00016.79
7.4.220.0060.01316.61
7.4.210.0090.01516.71
7.4.200.0040.00416.48
7.4.160.0160.00616.55
7.4.150.0110.00817.40
7.4.140.0110.00917.86
7.4.130.0120.01216.82
7.4.120.0100.01116.65
7.4.110.0080.00816.70
7.4.100.0100.01416.47
7.4.90.0090.00916.67
7.4.80.0180.00019.39
7.4.70.0130.00916.57
7.4.60.0120.00816.68
7.4.50.0030.00916.51
7.4.40.0110.00616.50
7.4.30.0070.01016.48
7.4.00.0000.01615.05
7.3.330.0000.00513.45
7.3.320.0030.00313.54
7.3.310.0000.00716.46
7.3.300.0000.00816.53
7.3.290.0080.00816.57
7.3.280.0100.00816.58
7.3.270.0120.01517.40
7.3.260.0100.00916.83
7.3.250.0090.01116.70
7.3.240.0060.01416.56
7.3.230.0080.01116.82
7.3.210.0060.01216.73
7.3.200.0130.00616.87
7.3.190.0110.00816.68
7.3.180.0040.01316.60
7.3.170.0130.00416.68
7.3.160.0080.00816.64
7.3.10.0050.00516.83
7.3.00.0030.00816.77
7.2.330.0130.00616.98
7.2.320.0040.02017.00
7.2.310.0180.00616.65
7.2.300.0150.00416.84
7.2.290.0100.00717.04
7.2.130.0000.01617.02
7.2.120.0030.01217.11
7.2.110.0070.00417.06
7.2.100.0080.00817.13
7.2.90.0120.00416.79
7.2.80.0030.00917.11
7.2.70.0030.00616.94
7.2.60.0030.00816.95
7.2.50.0070.00316.73
7.2.40.0060.00817.09
7.2.30.0040.01117.30
7.2.20.0030.00617.12
7.2.10.0030.01217.12
7.2.00.0100.00716.97
7.1.250.0090.00616.11
7.1.200.0070.00015.91
7.1.110.0200.01416.52
7.1.100.0460.00716.62
7.1.90.0290.00616.66
7.1.80.0220.01016.32
7.1.70.0390.00615.65
7.1.60.0630.01633.21
7.1.50.0640.01633.30
7.1.40.0380.01733.00
7.1.30.1270.01632.96
7.1.20.0290.02232.85
7.1.10.0220.01315.04
7.1.00.0280.00614.99
7.0.250.0370.00716.12
7.0.240.0330.01116.29
7.0.230.0230.01016.26
7.0.220.0190.01216.06
7.0.210.0390.01014.93
7.0.200.0310.01414.92
7.0.190.0400.01114.89
7.0.180.0700.00714.81
7.0.170.0280.01014.87
7.0.160.0250.01314.59
7.0.150.0250.00714.84
7.0.140.0370.01714.62
7.0.130.0340.01214.88
7.0.120.0330.01314.77
7.0.110.0250.01114.76
7.0.100.0230.01314.45
7.0.90.0310.00914.60
7.0.80.0340.01314.67
7.0.70.0300.00814.45
7.0.60.0370.01414.64
7.0.50.0280.00614.88
7.0.40.0280.00614.78
7.0.30.0290.00615.00
7.0.20.0280.00714.81
7.0.10.0280.01014.53
7.0.00.0400.00814.82

preferences:
54.41 ms | 400 KiB | 5 Q