3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Question { public $text; public $points = 5; public $answers; public $correctAnswer; public $hint; } function createQuestions() { $questions = []; $q = new Question; $q->text = "Какая планета располагается четвертой по счету от Солнца?"; $q->points = 10; // 10 баллов за ответ $q->answers = array('a' => 'Венера', 'b' => 'Марс', 'c' => 'Юпитер', 'd' => 'Меркурий'); // Варианты ответа $q->correctAnswer = 'b'; // Правильный ответ $q->hint = "Красная планета"; $questions[] = $q; $q = new Question; $q->text = 'Какой город является столицей Великобритании?'; $q->points = 5; $q->answers = array('a' => 'Париж', 'b' => 'Москва', 'c' => 'Нью-Йорк', 'd' => 'Лондон'); $q->correctAnswer = 'd'; $q->hint = "Биг Бен"; $questions[] = $q; $q = new Question; $q->text = 'Кто придумал теорию относительности?'; $q->points = 30; $q->answers = array('a' => 'Джон Леннон', 'b' => 'Джим Моррисон', 'c' => 'Альберт Эйнштейн', 'd' => 'Исаак Ньютон'); $q->correctAnswer = 'c'; $q->hint = "Высунул язык"; $questions[] = $q; return $questions; } function printQuestions($questions) { $number = 1; foreach ($questions as $question) { echo "{$number}. {$question->text}\n"; echo "Варианты ответов:\n"; foreach ($question->answers as $letter => $answer) { echo " {$letter}. {$answer}\n"; } echo "\n"; $number++; } } function checkAnswers($questions, $answers) { if (count($questions) != count($answers)) { die("Число ответов и вопросов не совпадает\n"); } $pointsTotal = 0; $pointsMax = 0; $correctAnswers = 0; $totalQuestions = count($questions); for ($i = 0; $i < count($questions); $i++) { $question = $questions[$i]; // Текущий вопрос $answer = $answers[$i]; // текущий ответ $pointsMax += $question->points; if ($answer == $question->correctAnswer) { $correctAnswers ++; $pointsTotal += $question->points; } else { $number = $i + 1; echo "Неправильный ответ на вопрос №{$number} ({$question->text} Подсказка: $question->hint) \n"; } } echo "Правильных ответов: {$correctAnswers} из {$totalQuestions}, баллов набрано: $pointsTotal из $pointsMax\n"; } $questions = createQuestions(); printQuestions($questions); $answers = array('b', 'd', 'a'); checkAnswers($questions, $answers);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dWVtb
function name:  (null)
number of ops:  12
compiled vars:  !0 = $questions, !1 = $answers
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   92     0  E >   INIT_FCALL                                                   'createquestions'
          1        DO_FCALL                                          0  $2      
          2        ASSIGN                                                       !0, $2
   93     3        INIT_FCALL                                                   'printquestions'
          4        SEND_VAR                                                     !0
          5        DO_FCALL                                          0          
   94     6        ASSIGN                                                       !1, <array>
   95     7        INIT_FCALL                                                   'checkanswers'
          8        SEND_VAR                                                     !0
          9        SEND_VAR                                                     !1
         10        DO_FCALL                                          0          
         11      > RETURN                                                       1

Function createquestions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dWVtb
function name:  createQuestions
number of ops:  48
compiled vars:  !0 = $questions, !1 = $q
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, <array>
   16     1        NEW                                                  $3      'Question'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $3
   17     4        ASSIGN_OBJ                                                   !1, 'text'
          5        OP_DATA                                                      '%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'
   18     6        ASSIGN_OBJ                                                   !1, 'points'
          7        OP_DATA                                                      10
   19     8        ASSIGN_OBJ                                                   !1, 'answers'
          9        OP_DATA                                                      <array>
   20    10        ASSIGN_OBJ                                                   !1, 'correctAnswer'
         11        OP_DATA                                                      'b'
   21    12        ASSIGN_OBJ                                                   !1, 'hint'
         13        OP_DATA                                                      '%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'
   23    14        ASSIGN_DIM                                                   !0
         15        OP_DATA                                                      !1
   25    16        NEW                                                  $12     'Question'
         17        DO_FCALL                                          0          
         18        ASSIGN                                                       !1, $12
   26    19        ASSIGN_OBJ                                                   !1, 'text'
         20        OP_DATA                                                      '%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'
   27    21        ASSIGN_OBJ                                                   !1, 'points'
         22        OP_DATA                                                      5
   28    23        ASSIGN_OBJ                                                   !1, 'answers'
         24        OP_DATA                                                      <array>
   29    25        ASSIGN_OBJ                                                   !1, 'correctAnswer'
         26        OP_DATA                                                      'd'
   30    27        ASSIGN_OBJ                                                   !1, 'hint'
         28        OP_DATA                                                      '%D0%91%D0%B8%D0%B3+%D0%91%D0%B5%D0%BD'
   32    29        ASSIGN_DIM                                                   !0
         30        OP_DATA                                                      !1
   34    31        NEW                                                  $21     'Question'
         32        DO_FCALL                                          0          
         33        ASSIGN                                                       !1, $21
   35    34        ASSIGN_OBJ                                                   !1, 'text'
         35        OP_DATA                                                      '%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'
   36    36        ASSIGN_OBJ                                                   !1, 'points'
         37        OP_DATA                                                      30
   37    38        ASSIGN_OBJ                                                   !1, 'answers'
         39        OP_DATA                                                      <array>
   38    40        ASSIGN_OBJ                                                   !1, 'correctAnswer'
         41        OP_DATA                                                      'c'
   39    42        ASSIGN_OBJ                                                   !1, 'hint'
         43        OP_DATA                                                      '%D0%92%D1%8B%D1%81%D1%83%D0%BD%D1%83%D0%BB+%D1%8F%D0%B7%D1%8B%D0%BA'
   41    44        ASSIGN_DIM                                                   !0
         45        OP_DATA                                                      !1
   43    46      > RETURN                                                       !0
   44    47*     > RETURN                                                       null

End of function createquestions

Function printquestions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/dWVtb
function name:  printQuestions
number of ops:  28
compiled vars:  !0 = $questions, !1 = $number, !2 = $question, !3 = $answer, !4 = $letter
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
   48     1        ASSIGN                                                       !1, 1
   50     2      > FE_RESET_R                                           $6      !0, ->26
          3    > > FE_FETCH_R                                                   $6, !2, ->26
   51     4    >   ROPE_INIT                                         4  ~9      !1
          5        ROPE_ADD                                          1  ~9      ~9, '.+'
          6        FETCH_OBJ_R                                          ~7      !2, 'text'
          7        ROPE_ADD                                          2  ~9      ~9, ~7
          8        ROPE_END                                          3  ~8      ~9, '%0A'
          9        ECHO                                                         ~8
   53    10        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%BE%D0%B2%3A%0A'
   55    11        FETCH_OBJ_R                                          ~11     !2, 'answers'
         12      > FE_RESET_R                                           $12     ~11, ->22
         13    > > FE_FETCH_R                                           ~13     $12, !3, ->22
         14    >   ASSIGN                                                       !4, ~13
   56    15        ROPE_INIT                                         5  ~16     '++'
         16        ROPE_ADD                                          1  ~16     ~16, !4
         17        ROPE_ADD                                          2  ~16     ~16, '.+'
         18        ROPE_ADD                                          3  ~16     ~16, !3
         19        ROPE_END                                          4  ~15     ~16, '%0A'
         20        ECHO                                                         ~15
   55    21      > JMP                                                          ->13
         22    >   FE_FREE                                                      $12
   58    23        ECHO                                                         '%0A'
   59    24        PRE_INC                                                      !1
   50    25      > JMP                                                          ->3
         26    >   FE_FREE                                                      $6
   61    27      > RETURN                                                       null

End of function printquestions

Function checkanswers:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 16
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 16
Branch analysis from position: 45
Branch analysis from position: 16
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 16
Branch analysis from position: 45
Branch analysis from position: 16
filename:       /in/dWVtb
function name:  checkAnswers
number of ops:  56
compiled vars:  !0 = $questions, !1 = $answers, !2 = $pointsTotal, !3 = $pointsMax, !4 = $correctAnswers, !5 = $totalQuestions, !6 = $i, !7 = $question, !8 = $answer, !9 = $number
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   63     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   65     2        COUNT                                                ~10     !0
          3        COUNT                                                ~11     !1
          4        IS_NOT_EQUAL                                                 ~10, ~11
          5      > JMPZ                                                         ~12, ->9
   66     6    > > INIT_FCALL                                                   'exit'
          7*       SEND_VAL                                                     '%D0%A7%D0%B8%D1%81%D0%BB%D0%BE+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%BE%D0%B2+%D0%B8+%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D0%BE%D0%B2+%D0%BD%D0%B5+%D1%81%D0%BE%D0%B2%D0%BF%D0%B0%D0%B4%D0%B0%D0%B5%D1%82%0A'
          8*       DO_ICALL                                                     
   69     9    >   ASSIGN                                                       !2, 0
   70    10        ASSIGN                                                       !3, 0
   71    11        ASSIGN                                                       !4, 0
   72    12        COUNT                                                ~17     !0
         13        ASSIGN                                                       !5, ~17
   74    14        ASSIGN                                                       !6, 0
         15      > JMP                                                          ->42
   75    16    >   FETCH_DIM_R                                          ~20     !0, !6
         17        ASSIGN                                                       !7, ~20
   76    18        FETCH_DIM_R                                          ~22     !1, !6
         19        ASSIGN                                                       !8, ~22
   78    20        FETCH_OBJ_R                                          ~24     !7, 'points'
         21        ASSIGN_OP                                         1          !3, ~24
   80    22        FETCH_OBJ_R                                          ~26     !7, 'correctAnswer'
         23        IS_EQUAL                                                     !8, ~26
         24      > JMPZ                                                         ~27, ->29
   81    25    >   PRE_INC                                                      !4
   82    26        FETCH_OBJ_R                                          ~29     !7, 'points'
         27        ASSIGN_OP                                         1          !2, ~29
   80    28      > JMP                                                          ->41
   84    29    >   ADD                                                  ~31     !6, 1
         30        ASSIGN                                                       !9, ~31
   85    31        ROPE_INIT                                         7  ~36     '%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'
         32        ROPE_ADD                                          1  ~36     ~36, !9
         33        ROPE_ADD                                          2  ~36     ~36, '+%28'
         34        FETCH_OBJ_R                                          ~33     !7, 'text'
         35        ROPE_ADD                                          3  ~36     ~36, ~33
         36        ROPE_ADD                                          4  ~36     ~36, '+%D0%9F%D0%BE%D0%B4%D1%81%D0%BA%D0%B0%D0%B7%D0%BA%D0%B0%3A+'
         37        FETCH_OBJ_R                                          ~34     !7, 'hint'
         38        ROPE_ADD                                          5  ~36     ~36, ~34
         39        ROPE_END                                          6  ~35     ~36, '%29+%0A'
         40        ECHO                                                         ~35
   74    41    >   PRE_INC                                                      !6
         42    >   COUNT                                                ~41     !0
         43        IS_SMALLER                                                   !6, ~41
         44      > JMPNZ                                                        ~42, ->16
   89    45    >   ROPE_INIT                                         9  ~44     '%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+'
         46        ROPE_ADD                                          1  ~44     ~44, !4
         47        ROPE_ADD                                          2  ~44     ~44, '+%D0%B8%D0%B7+'
         48        ROPE_ADD                                          3  ~44     ~44, !5
         49        ROPE_ADD                                          4  ~44     ~44, '%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+'
         50        ROPE_ADD                                          5  ~44     ~44, !2
         51        ROPE_ADD                                          6  ~44     ~44, '+%D0%B8%D0%B7+'
         52        ROPE_ADD                                          7  ~44     ~44, !3
         53        ROPE_END                                          8  ~43     ~44, '%0A'
         54        ECHO                                                         ~43
   90    55      > RETURN                                                       null

End of function checkanswers

Class Question: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
287.18 ms | 2535 KiB | 17 Q