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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  (null)
number of ops:  46
compiled vars:  !0 = $q1, !1 = $q2, !2 = $q3, !3 = $q4, !4 = $questions, !5 = $answers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   NEW                                              $6      'ChoiceQuestion'
          1        SEND_VAL_EX                                              '%D0%9A%D0%B0%D0%BA%D0%B0%D1%8F+%D0%BF%D0%BB%D0%B0%D0%BD%D0%B5%D1%82%D0%B0+%D1%80%D0%B0%D1%81%D0%BF%D0%BE%D0%BB%D0%B0%D0%B3%D0%B0%D0%B5%D1%82%D1%81%D1%8F+%D1%87%D0%B5%D1%82%D0%B2%D0%B5%D1%80%D1%82%D0%BE%D0%B9+%D0%BF%D0%BE+%D1%81%D1%87%D0%B5%D1%82%D1%83+%D0%BE%D1%82+%D0%A1%D0%BE%D0%BB%D0%BD%D1%86%D0%B0%3F'
          2        SEND_VAL_EX                                              <array>
          3        SEND_VAL_EX                                              'b'
          4        SEND_VAL_EX                                              '%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%B0%D1%8F+%D0%BF%D0%BB%D0%B0%D0%BD%D0%B5%D1%82%D0%B0'
          5        SEND_VAL_EX                                              10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $6
  100     8        NEW                                              $9      'ChoiceQuestion'
          9        SEND_VAL_EX                                              '%D0%9A%D0%B0%D0%BA%D0%BE%D0%B9+%D0%B3%D0%BE%D1%80%D0%BE%D0%B4+%D1%8F%D0%B2%D0%BB%D1%8F%D0%B5%D1%82%D1%81%D1%8F+%D1%81%D1%82%D0%BE%D0%BB%D0%B8%D1%86%D0%B5%D0%B9+%D0%92%D0%B5%D0%BB%D0%B8%D0%BA%D0%BE%D0%B1%D1%80%D0%B8%D1%82%D0%B0%D0%BD%D0%B8%D0%B8%3F'
         10        SEND_VAL_EX                                              <array>
         11        SEND_VAL_EX                                              'd'
         12        SEND_VAL_EX                                              '%D0%A2%D0%B0%D0%BC+%D0%B5%D1%89%D1%91+%D0%BA%D0%BE%D1%80%D0%BE%D0%BB%D0%B5%D0%B2%D0%B0+%D0%B5%D1%81%D1%82%D1%8C'
         13        SEND_VAL_EX                                              5
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $9
  101    16        NEW                                              $12     'NumericQuestion'
         17        SEND_VAL_EX                                              '%D0%A7%D0%B5%D0%BC%D1%83+%D1%80%D0%B0%D0%B2%D0%BD%D0%B0+%D1%81%D0%BA%D0%BE%D1%80%D0%BE%D1%81%D1%82%D1%8C+%D1%81%D0%B2%D0%B5%D1%82%D0%B0+%D0%B2+%D0%BA%D0%BC%2F%D1%81%3F'
         18        SEND_VAL_EX                                              300000
         19        SEND_VAL_EX                                              1000
         20        SEND_VAL_EX                                              '%D0%9E%D1%82%D1%81%D0%BE%D1%81%D0%B8+%D1%83+%D1%82%D1%80%D0%B0%D0%BA%D1%82%D0%BE%D1%80%D0%B8%D1%81%D1%82%D0%B0'
         21        SEND_VAL_EX                                              10
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $12
  102    24        NEW                                              $15     'ChoiceQuestion'
         25        SEND_VAL_EX                                              '%D0%9A%D1%82%D0%BE+%D0%BF%D1%80%D0%B8%D0%B4%D1%83%D0%BC%D0%B0%D0%BB+%D1%82%D0%B5%D0%BE%D1%80%D0%B8%D1%8E+%D0%BE%D1%82%D0%BD%D0%BE%D1%81%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%BE%D1%81%D1%82%D0%B8%3F'
         26        SEND_VAL_EX                                              <array>
         27        SEND_VAL_EX                                              'c'
         28        SEND_VAL_EX                                              '%D0%9F%D0%BE%D0%BA%D0%B0%D0%B7%D1%8B%D0%B2%D0%B0%D0%BB+%D1%8F%D0%B7%D1%8B%D0%BA'
         29        SEND_VAL_EX                                              30
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !3, $15
  104    32        INIT_ARRAY                                       ~18     !0
         33        ADD_ARRAY_ELEMENT                                ~18     !1
         34        ADD_ARRAY_ELEMENT                                ~18     !2
         35        ADD_ARRAY_ELEMENT                                ~18     !3
         36        ASSIGN                                                   !4, ~18
  105    37        INIT_FCALL                                               'printquestions'
         38        SEND_VAR                                                 !4
         39        DO_FCALL                                      0          
  107    40        ASSIGN                                                   !5, <array>
  108    41        INIT_FCALL                                               'checkanswers'
         42        SEND_VAR                                                 !5
         43        SEND_VAR                                                 !4
         44        DO_FCALL                                      0          
         45      > RETURN                                                   1

Function printquestions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/4GGth
function name:  printQuestions
number of ops:  12
compiled vars:  !0 = $questions, !1 = $question, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   70     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->10
          3    >   ASSIGN                                                   !2, ~4
   71     4        ADD                                              ~6      !2, 1
          5        ECHO                                                     ~6
   72     6        ECHO                                                     '.+'
   73     7        INIT_METHOD_CALL                                         !1, 'printQuestion'
          8        DO_FCALL                                      0          
   70     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   75    11      > RETURN                                                   null

End of function printquestions

Function checkanswers:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 37
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 37
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/4GGth
function name:  checkAnswers
number of ops:  48
compiled vars:  !0 = $answers, !1 = $questions, !2 = $maxPoints, !3 = $points, !4 = $countOfCorrentAnswers, !5 = $maxAnswers, !6 = $question, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   78     2        ASSIGN                                                   !2, 0
   79     3        ASSIGN                                                   !3, 0
   80     4        ASSIGN                                                   !4, 0
   81     5        ASSIGN                                                   !5, 0
   83     6      > FE_RESET_R                                       $12     !1, ->37
          7    > > FE_FETCH_R                                       ~13     $12, !6, ->37
          8    >   ASSIGN                                                   !7, ~13
   84     9        INIT_METHOD_CALL                                         !6, 'checkAnswer'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $15     !0, !7
         12        SEND_FUNC_ARG                                            $15
         13        DO_FCALL                                      0  $16     
         14        BOOL                                             ~17     $16
         15      > JMPZ                                                     ~17, ->20
   85    16    >   FETCH_OBJ_R                                      ~18     !6, 'points'
         17        ASSIGN_OP                                     1          !3, ~18
   86    18        PRE_INC                                                  !4
         19      > JMP                                                      ->33
   88    20    >   ECHO                                                     '%D0%9D%D0%B5%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BE%D1%82%D0%B2%D0%B5%D1%82+%D0%BD%D0%B0+%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81+%E2%84%96'
   89    21        ADD                                              ~21     !7, 1
         22        ECHO                                                     ~21
   90    23        ROPE_INIT                                     3  ~24     '+%28'
         24        FETCH_OBJ_R                                      ~22     !6, 'text'
         25        ROPE_ADD                                      1  ~24     ~24, ~22
         26        ROPE_END                                      2  ~23     ~24, '%29%0A'
         27        ECHO                                                     ~23
   91    28        ROPE_INIT                                     3  ~28     '%D0%9F%D0%BE%D0%B4%D1%81%D0%BA%D0%B0%D0%B7%D0%BA%D0%B0%3A+'
         29        FETCH_OBJ_R                                      ~26     !6, 'hint'
         30        ROPE_ADD                                      1  ~28     ~28, ~26
         31        ROPE_END                                      2  ~27     ~28, '%0A'
         32        ECHO                                                     ~27
   93    33    >   FETCH_OBJ_R                                      ~30     !6, 'points'
         34        ASSIGN_OP                                     1          !2, ~30
   94    35        PRE_INC                                                  !5
   83    36      > JMP                                                      ->7
         37    >   FE_FREE                                                  $12
   96    38        ROPE_INIT                                     8  ~34     '%0A%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D1%85+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%BE%D0%B2%3A+'
         39        ROPE_ADD                                      1  ~34     ~34, !4
         40        ROPE_ADD                                      2  ~34     ~34, '+%D0%B8%D0%B7+'
         41        ROPE_ADD                                      3  ~34     ~34, !5
         42        ROPE_ADD                                      4  ~34     ~34, '%2C+%D0%B1%D0%B0%D0%BB%D0%BB%D0%BE%D0%B2+%D0%BD%D0%B0%D0%B1%D1%80%D0%B0%D0%BD%D0%BE%3A+'
         43        ROPE_ADD                                      5  ~34     ~34, !3
         44        ROPE_ADD                                      6  ~34     ~34, '+%D0%B8%D0%B7+'
         45        ROPE_END                                      7  ~33     ~34, !2
         46        ECHO                                                     ~33
   97    47      > RETURN                                                   null

End of function checkanswers

Class AbstractQuestion:
Function checkanswer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  checkAnswer
number of ops:  2
compiled vars:  !0 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function checkanswer

Function printquestion:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  printQuestion
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   null

End of function printquestion

End of class AbstractQuestion.

Class ChoiceQuestion:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  __construct
number of ops:  16
compiled vars:  !0 = $text, !1 = $answers, !2 = $correctAnswer, !3 = $hint, !4 = $points
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   19     5        ASSIGN_OBJ                                               'text'
          6        OP_DATA                                                  !0
   20     7        ASSIGN_OBJ                                               'answers'
          8        OP_DATA                                                  !1
   21     9        ASSIGN_OBJ                                               'correctAnswer'
         10        OP_DATA                                                  !2
   22    11        ASSIGN_OBJ                                               'hint'
         12        OP_DATA                                                  !3
   23    13        ASSIGN_OBJ                                               'points'
         14        OP_DATA                                                  !4
   24    15      > RETURN                                                   null

End of function __construct

Function printquestion:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/4GGth
function name:  printQuestion
number of ops:  17
compiled vars:  !0 = $answer, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~2      'text'
          1        CONCAT                                           ~3      ~2, '%0A'
          2        ECHO                                                     ~3
   28     3        ECHO                                                     '%D0%92%D0%B0%D1%80%D0%B8%D0%B0%D0%BD%D1%82%D1%8B+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%B0%3A%0A'
   29     4        FETCH_OBJ_R                                      ~4      'answers'
          5      > FE_RESET_R                                       $5      ~4, ->14
          6    > > FE_FETCH_R                                       ~6      $5, !0, ->14
          7    >   ASSIGN                                                   !1, ~6
   30     8        ROPE_INIT                                     4  ~9      !1
          9        ROPE_ADD                                      1  ~9      ~9, '.+'
         10        ROPE_ADD                                      2  ~9      ~9, !0
         11        ROPE_END                                      3  ~8      ~9, '%0A'
         12        ECHO                                                     ~8
   29    13      > JMP                                                      ->6
         14    >   FE_FREE                                                  $5
   32    15        ECHO                                                     '%0A'
   33    16      > RETURN                                                   null

End of function printquestion

Function checkanswer:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  checkAnswer
number of ops:  8
compiled vars:  !0 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        FETCH_OBJ_R                                      ~1      'correctAnswer'
          2        IS_EQUAL                                                 !0, ~1
          3      > JMPZ                                                     ~2, ->6
   37     4    > > RETURN                                                   <true>
          5*       JMP                                                      ->7
   39     6    > > RETURN                                                   <false>
   41     7*     > RETURN                                                   null

End of function checkanswer

End of class ChoiceQuestion.

Class NumericQuestion:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  __construct
number of ops:  16
compiled vars:  !0 = $text, !1 = $correctAnswer, !2 = $deviation, !3 = $hint, !4 = $points
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   49     5        ASSIGN_OBJ                                               'text'
          6        OP_DATA                                                  !0
   50     7        ASSIGN_OBJ                                               'correctAnswer'
          8        OP_DATA                                                  !1
   51     9        ASSIGN_OBJ                                               'deviation'
         10        OP_DATA                                                  !2
   52    11        ASSIGN_OBJ                                               'hint'
         12        OP_DATA                                                  !3
   53    13        ASSIGN_OBJ                                               'points'
         14        OP_DATA                                                  !4
   54    15      > RETURN                                                   null

End of function __construct

Function printquestion:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4GGth
function name:  printQuestion
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   FETCH_OBJ_R                                      ~0      'text'
          1        ECHO                                                     ~0
          2        ECHO                                                     '%0A%0A'
   58     3      > RETURN                                                   null

End of function printquestion

Function checkanswer:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/4GGth
function name:  checkAnswer
number of ops:  16
compiled vars:  !0 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   61     1        FETCH_OBJ_R                                      ~1      'correctAnswer'
          2        FETCH_OBJ_R                                      ~2      'deviation'
          3        ADD                                              ~3      ~1, ~2
          4        IS_SMALLER_OR_EQUAL                              ~4      !0, ~3
          5      > JMPZ_EX                                          ~4      ~4, ->11
          6    >   FETCH_OBJ_R                                      ~5      'correctAnswer'
          7        FETCH_OBJ_R                                      ~6      'deviation'
          8        SUB                                              ~7      ~5, ~6
          9        IS_SMALLER_OR_EQUAL                              ~8      ~7, !0
         10        BOOL                                             ~4      ~8
         11    > > JMPZ                                                     ~4, ->14
   62    12    > > RETURN                                                   <true>
         13*       JMP                                                      ->15
   64    14    > > RETURN                                                   <false>
   66    15*     > RETURN                                                   null

End of function checkanswer

End of class NumericQuestion.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.03 ms | 1419 KiB | 15 Q