3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AbstractQuestion { public $text; public $points; public $hint; public $correctAnswer; abstract function checkAnswer($answer); abstract function printQuestion(); } class ChoiceQuestion extends AbstractQuestion { public $answers = array(); public function __construct(string $text, array $answers, string $correctAnswer, string $hint, int $points) { $this->text = $text; $this->answers = $answers; $this->correctAnswer = $correctAnswer; $this->hint = $hint; $this->points = $points; } public function printQuestion() { echo $this->text."\n"; echo "Варианты ответа:\n"; foreach ($this->answers as $key => $answer) { echo "$key. $answer\n"; } echo "\n"; } public function checkAnswer($answer) { if ($answer == $this->correctAnswer) { return TRUE; } else { return FALSE; } } } class NumericQuestion extends AbstractQuestion { public $deviation; public function __construct(string $text, int $correctAnswer, int $deviation, string $hint, int $points) { $this->text = $text; $this->correctAnswer = $correctAnswer; $this->deviation = $deviation; $this->hint = $hint; $this->points = $points; } public function printQuestion() { echo $this->text, "\n\n"; } public function checkAnswer($answer) { if ($answer <= $this->correctAnswer + $this->deviation && $answer >= $this->correctAnswer - $this->deviation) { return TRUE; } else { return FALSE; } } } function printQuestions(array $questions) { foreach ($questions as $key => $question) { echo $key + 1; echo ". "; $question->printQuestion(); } } function checkAnswers (array $answers, array $questions) { $maxPoints = 0; $points = 0; $countOfCorrentAnswers = 0; $maxAnswers = 0; foreach ($questions as $key => $question) { if ($question->checkAnswer($answers[$key]) == TRUE) { $points += $question->points; $countOfCorrentAnswers++; } else { echo "Неправильный ответ на вопрос №"; echo $key + 1; echo " ($question->text)\n"; echo "Подсказка: $question->hint\n"; } $maxPoints += $question->points; $maxAnswers++; } echo "\nПравильных ответов: $countOfCorrentAnswers из $maxAnswers, баллов набрано: $points из $maxPoints"; } $q1 = new ChoiceQuestion ("Какая планета располагается четвертой по счету от Солнца?", array('a' => 'Венера', 'b' => 'Марс', 'c' => 'Юпитер', 'd' => 'Меркурий'), 'b', "Красная планета", 10); $q2 = new ChoiceQuestion ("Какой город является столицей Великобритании?", array('a' => 'Париж', 'b' => 'Москва', 'c' => 'Нью-Йорк', 'd' => 'Лондон'), 'd', "Там ещё королева есть", 5); $q3 = new NumericQuestion ("Чему равна скорость света в км/с?", 300000, 1000, "Отсоси у тракториста", 10); $q4 = new ChoiceQuestion ("Кто придумал теорию относительности?", array('a' => 'Джон Леннон', 'b' => 'Джим Моррисон', 'c' => 'Альберт Эйнштейн', 'd' => 'Исаак Ньютон'), 'c', "Показывал язык", 30); $questions = array($q1, $q2, $q3, $q4); printQuestions($questions); $answers = array('b', 'c', 299000, 'c'); checkAnswers($answers, $questions);

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.0220.00616.88
8.3.50.0120.00918.04
8.3.40.0120.00418.80
8.3.30.0110.00418.63
8.3.20.0050.00320.99
8.3.10.0000.00920.53
8.3.00.0030.00620.90
8.2.180.0060.00918.28
8.2.170.0160.00622.96
8.2.160.0150.00022.96
8.2.150.0000.00824.18
8.2.140.0030.00524.66
8.2.130.0080.00026.16
8.2.120.0040.00420.35
8.2.110.0030.00621.13
8.2.100.0040.00817.88
8.2.90.0040.00417.96
8.2.80.0030.00618.03
8.2.70.0000.00917.93
8.2.60.0050.00318.03
8.2.50.0040.00418.10
8.2.40.0040.00419.30
8.2.30.0040.00419.34
8.2.20.0040.00418.15
8.2.10.0040.00419.57
8.2.00.0040.00418.14
8.1.270.0080.00020.45
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00622.46
8.1.230.0070.00420.97
8.1.220.0050.00317.74
8.1.210.0000.00818.85
8.1.200.0030.00717.25
8.1.190.0080.00017.29
8.1.180.0040.00418.10
8.1.170.0040.00418.66
8.1.160.0020.00518.81
8.1.150.0000.00718.91
8.1.140.0000.00820.20
8.1.130.0070.00017.39
8.1.120.0000.00717.49
8.1.110.0000.00717.49
8.1.100.0000.00817.50
8.1.90.0040.00417.43
8.1.80.0030.00617.39
8.1.70.0040.00417.54
8.1.60.0060.00317.63
8.1.50.0000.00817.56
8.1.40.0000.00817.54
8.1.30.0030.00517.68
8.1.20.0030.00617.68
8.1.10.0070.00317.50
8.1.00.0000.00917.36
8.0.300.0040.00419.63
8.0.290.0090.00016.63
8.0.280.0070.00018.49
8.0.270.0030.00316.77
8.0.260.0000.00716.86
8.0.250.0030.00316.99
8.0.240.0000.00716.98
8.0.230.0030.00317.00
8.0.220.0030.00316.96
8.0.210.0040.00416.85
8.0.200.0050.00317.02
8.0.190.0030.00516.89
8.0.180.0040.00416.98
8.0.170.0090.00016.99
8.0.160.0020.00517.03
8.0.150.0040.00416.82
8.0.140.0000.00716.91
8.0.130.0000.00513.31
8.0.120.0000.00816.92
8.0.110.0040.00416.95
8.0.100.0070.00016.77
8.0.90.0040.00416.86
8.0.80.0040.01116.85
8.0.70.0000.00716.91
8.0.60.0000.00816.80
8.0.50.0040.00416.88
8.0.30.0100.01017.17
8.0.20.0060.01317.40
8.0.10.0000.00717.08
8.0.00.0090.01116.74
7.4.330.0000.00615.55
7.4.320.0000.00716.47
7.4.300.0000.00616.54
7.4.290.0030.00516.62
7.4.280.0000.00916.64
7.4.270.0040.00816.51
7.4.260.0050.00316.63
7.4.250.0030.00316.49
7.4.240.0000.00716.59
7.4.230.0000.00716.65
7.4.220.0030.00516.28
7.4.210.0100.00716.56
7.4.200.0070.00016.38
7.4.160.0130.00616.57
7.4.140.0140.00517.86
7.4.130.0350.02516.38
7.4.120.0130.00916.54
7.4.110.0120.00716.82
7.4.100.0000.01816.55
7.4.90.0110.00816.44
7.4.80.0050.01119.39
7.4.70.0090.00616.51
7.4.60.0030.01216.48
7.4.50.0110.00416.66
7.4.40.0130.01016.22
7.4.00.0070.01015.17
7.3.330.0050.00013.38
7.3.320.0000.00613.37
7.3.310.0040.00416.29
7.3.300.0050.00316.41
7.3.290.0030.00316.41
7.3.280.0090.00816.35
7.3.260.0130.00716.49
7.3.240.0100.00816.47
7.3.230.0060.01016.70
7.3.210.0070.01016.45
7.3.200.0030.01516.33
7.3.190.0130.00616.39
7.3.180.0150.00416.64
7.3.170.0060.01216.39
7.3.160.0160.00016.51
7.3.20.0690.00714.77
7.3.10.0720.00014.75
7.3.00.0680.00314.91
7.2.330.0080.01016.77
7.2.320.0130.01016.86
7.2.310.0170.00016.81
7.2.300.0090.00916.54
7.2.290.0050.01416.95
7.2.150.0870.00615.33
7.2.140.0590.00714.90
7.2.130.0530.01015.17
7.2.120.0560.00715.08
7.2.110.0590.00715.21
7.2.100.0600.00015.18
7.2.90.0580.00714.87
7.2.80.0510.01014.99
7.2.70.0700.00315.05
7.2.60.0790.01015.31
7.2.50.0810.01314.93
7.2.40.0590.00315.09
7.2.30.0560.00615.25
7.2.20.0820.01015.23
7.2.10.0690.00015.23
7.2.00.0630.00315.18
7.1.250.0470.01314.14

preferences:
67.45 ms | 400 KiB | 5 Q