3v4l.org

run code in 300+ PHP versions simultaneously
<?php session_start(); define('ROCK' , 0); define('SCISSORS', 1); define('PAPER' , 2); // セッション初期化 if (!isset($_SESSION['result'])) { $_SESSION['result'] = array(); } // 入力が渡されたとき if (isset($_POST['you'])) { // CPUの手を生成 $cpu = mt_rand(0, 2); // 不正アクセスで変な値がPOSTされても絶対に0~2の整数になるようにする $you = (int)$_POST['you'] % 3; // 結果を判定 switch (true) { case $you === $cpu : $msg = 'あいこ'; $_SESSION['result'][] = 'あいこ'; break; case $you === ROCK && $cpu === SCISSORS : case $you === SCISSORS && $cpu === PAPER : case $you === PAPER && $cpu === ROCK : $msg = 'あなたの勝ちです'; $_SESSION['result'][] = '勝ち'; break; default: $msg = 'あなたの負けです'; $_SESSION['result'][] = '負け'; } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>じゃんけん</title> </head> <body> <form method="post" action="<?php echo basename($_SERVER['SCRIPT_NAME']); ?>"> <fieldset> <legend>PHPと勝負!</legend> <div><input type="radio" name="you" value="0" />グー</div> <div><input type="radio" name="you" value="1" />チョキ</div> <div><input type="radio" name="you" value="2" />パー</div> </fieldset> </form> <fieldset> <legend>結果</legend> <?php if ($_SESSION['result']) { $r_you = end($_SESSION['result']); $r_cpu = $s_you === '勝ち' ? '負け' : '勝ち' ; echo '<p>'.$msg.'</p>'.PHP_EOL; echo '<table border="1">'.PHP_EOL; echo '<tr><th>あなた</th><th>vs</th><th>PHP</th></tr>'.PHP_EOL; foreach ($_SESSION['result'] as $result) { printf('<tr><td>%s</td><td> </td><td>%s</td></tr>', $r_you, $r_cpu); } echo '</table>'.PHP_EOL; } else { echo '結果がまだありません。'.PHP_EOL; } ?> </fieldset> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 75
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 58
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 39, Position 2 = 42
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 64
Branch analysis from position: 43
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 64
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 53, Position 2 = 56
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 64
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 117
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 94, Position 2 = 96
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
2 jumps found. (Code = 77) Position 1 = 107, Position 2 = 114
Branch analysis from position: 107
2 jumps found. (Code = 78) Position 1 = 108, Position 2 = 114
Branch analysis from position: 108
1 jumps found. (Code = 42) Position 1 = 107
Branch analysis from position: 107
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 114
Branch analysis from position: 96
2 jumps found. (Code = 77) Position 1 = 107, Position 2 = 114
Branch analysis from position: 107
Branch analysis from position: 114
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
Branch analysis from position: 56
Branch analysis from position: 64
Branch analysis from position: 49
Branch analysis from position: 64
Branch analysis from position: 42
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
Branch analysis from position: 75
Branch analysis from position: 21
filename:       /in/QhrEn
function name:  (null)
number of ops:  120
compiled vars:  !0 = $cpu, !1 = $you, !2 = $msg, !3 = $r_you, !4 = $r_cpu, !5 = $s_you, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'session_start'
          1        DO_ICALL                                                 
    5     2        INIT_FCALL                                               'define'
          3        SEND_VAL                                                 'ROCK'
          4        SEND_VAL                                                 0
          5        DO_ICALL                                                 
    6     6        INIT_FCALL                                               'define'
          7        SEND_VAL                                                 'SCISSORS'
          8        SEND_VAL                                                 1
          9        DO_ICALL                                                 
    7    10        INIT_FCALL                                               'define'
         11        SEND_VAL                                                 'PAPER'
         12        SEND_VAL                                                 2
         13        DO_ICALL                                                 
   10    14        FETCH_IS                                         ~11     '_SESSION'
         15        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     ~11, 'result'
         16        BOOL_NOT                                         ~13     ~12
         17      > JMPZ                                                     ~13, ->21
   11    18    >   FETCH_W                      global              $14     '_SESSION'
         19        ASSIGN_DIM                                               $14, 'result'
         20        OP_DATA                                                  <array>
   15    21    >   FETCH_IS                                         ~16     '_POST'
         22        ISSET_ISEMPTY_DIM_OBJ                         0          ~16, 'you'
         23      > JMPZ                                                     ~17, ->75
   18    24    >   INIT_FCALL                                               'mt_rand'
         25        SEND_VAL                                                 0
         26        SEND_VAL                                                 2
         27        DO_ICALL                                         $18     
         28        ASSIGN                                                   !0, $18
   21    29        FETCH_R                      global              ~20     '_POST'
         30        FETCH_DIM_R                                      ~21     ~20, 'you'
         31        CAST                                          4  ~22     ~21
         32        MOD                                              ~23     ~22, 3
         33        ASSIGN                                                   !1, ~23
   26    34        IS_IDENTICAL                                             !1, !0
         35      > JMPNZ                                                    ~26, ->58
   31    36    >   FETCH_CONSTANT                                   ~27     'ROCK'
         37        IS_IDENTICAL                                     ~28     !1, ~27
         38      > JMPZ_EX                                          ~28     ~28, ->42
         39    >   FETCH_CONSTANT                                   ~29     'SCISSORS'
         40        IS_IDENTICAL                                     ~30     !0, ~29
         41        BOOL                                             ~28     ~30
         42    > > JMPNZ                                                    ~28, ->64
   32    43    >   FETCH_CONSTANT                                   ~31     'SCISSORS'
         44        IS_IDENTICAL                                     ~32     !1, ~31
         45      > JMPZ_EX                                          ~32     ~32, ->49
         46    >   FETCH_CONSTANT                                   ~33     'PAPER'
         47        IS_IDENTICAL                                     ~34     !0, ~33
         48        BOOL                                             ~32     ~34
         49    > > JMPNZ                                                    ~32, ->64
   33    50    >   FETCH_CONSTANT                                   ~35     'PAPER'
         51        IS_IDENTICAL                                     ~36     !1, ~35
         52      > JMPZ_EX                                          ~36     ~36, ->56
         53    >   FETCH_CONSTANT                                   ~37     'ROCK'
         54        IS_IDENTICAL                                     ~38     !0, ~37
         55        BOOL                                             ~36     ~38
         56    > > JMPNZ                                                    ~36, ->64
         57    > > JMP                                                      ->70
   27    58    >   ASSIGN                                                   !2, '%E3%81%82%E3%81%84%E3%81%93'
   28    59        FETCH_W                      global              $40     '_SESSION'
         60        FETCH_DIM_W                                      $41     $40, 'result'
         61        ASSIGN_DIM                                               $41
         62        OP_DATA                                                  '%E3%81%82%E3%81%84%E3%81%93'
   29    63      > JMP                                                      ->75
   34    64    >   ASSIGN                                                   !2, '%E3%81%82%E3%81%AA%E3%81%9F%E3%81%AE%E5%8B%9D%E3%81%A1%E3%81%A7%E3%81%99'
   35    65        FETCH_W                      global              $44     '_SESSION'
         66        FETCH_DIM_W                                      $45     $44, 'result'
         67        ASSIGN_DIM                                               $45
         68        OP_DATA                                                  '%E5%8B%9D%E3%81%A1'
   36    69      > JMP                                                      ->75
   39    70    >   ASSIGN                                                   !2, '%E3%81%82%E3%81%AA%E3%81%9F%E3%81%AE%E8%B2%A0%E3%81%91%E3%81%A7%E3%81%99'
   40    71        FETCH_W                      global              $48     '_SESSION'
         72        FETCH_DIM_W                                      $49     $48, 'result'
         73        ASSIGN_DIM                                               $49
         74        OP_DATA                                                  '%E8%B2%A0%E3%81%91'
   47    75    >   ECHO                                                     '%3C%21DOCTYPE+html%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%3Cmeta+charset%3D%22UTF-8%22+%2F%3E%0A%3Ctitle%3E%E3%81%98%E3%82%83%E3%82%93%E3%81%91%E3%82%93%3C%2Ftitle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%3Cform+method%3D%22post%22+action%3D%22'
   54    76        INIT_FCALL                                               'basename'
         77        FETCH_R                      global              ~51     '_SERVER'
         78        FETCH_DIM_R                                      ~52     ~51, 'SCRIPT_NAME'
         79        SEND_VAL                                                 ~52
         80        DO_ICALL                                         $53     
         81        ECHO                                                     $53
         82        ECHO                                                     '%22%3E%0A%3Cfieldset%3E%0A%3Clegend%3EPHP%E3%81%A8%E5%8B%9D%E8%B2%A0%EF%BC%81%3C%2Flegend%3E%0A%3Cdiv%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%220%22+%2F%3E%E3%82%B0%E3%83%BC%3C%2Fdiv%3E%0A%3Cdiv%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%221%22+%2F%3E%E3%83%81%E3%83%A7%E3%82%AD%3C%2Fdiv%3E%0A%3Cdiv%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%222%22+%2F%3E%E3%83%91%E3%83%BC%3C%2Fdiv%3E%0A%3C%2Ffieldset%3E%0A%3C%2Fform%3E%0A%3Cfieldset%3E%0A%3Clegend%3E%E7%B5%90%E6%9E%9C%3C%2Flegend%3E%0A'
   66    83        FETCH_R                      global              ~54     '_SESSION'
         84        FETCH_DIM_R                                      ~55     ~54, 'result'
         85      > JMPZ                                                     ~55, ->117
   68    86    >   INIT_FCALL                                               'end'
         87        FETCH_W                      global              $56     '_SESSION'
         88        FETCH_DIM_W                                      $57     $56, 'result'
         89        SEND_REF                                                 $57
         90        DO_ICALL                                         $58     
         91        ASSIGN                                                   !3, $58
   69    92        IS_IDENTICAL                                             !5, '%E5%8B%9D%E3%81%A1'
         93      > JMPZ                                                     ~60, ->96
         94    >   QM_ASSIGN                                        ~61     '%E8%B2%A0%E3%81%91'
         95      > JMP                                                      ->97
         96    >   QM_ASSIGN                                        ~61     '%E5%8B%9D%E3%81%A1'
         97    >   ASSIGN                                                   !4, ~61
   71    98        CONCAT                                           ~63     '%3Cp%3E', !2
         99        CONCAT                                           ~64     ~63, '%3C%2Fp%3E'
        100        CONCAT                                           ~65     ~64, '%0A'
        101        ECHO                                                     ~65
   72   102        ECHO                                                     '%3Ctable+border%3D%221%22%3E%0A'
   73   103        ECHO                                                     '%3Ctr%3E%3Cth%3E%E3%81%82%E3%81%AA%E3%81%9F%3C%2Fth%3E%3Cth%3Evs%3C%2Fth%3E%3Cth%3EPHP%3C%2Fth%3E%3C%2Ftr%3E%0A'
   75   104        FETCH_R                      global              ~66     '_SESSION'
        105        FETCH_DIM_R                                      ~67     ~66, 'result'
        106      > FE_RESET_R                                       $68     ~67, ->114
        107    > > FE_FETCH_R                                               $68, !6, ->114
   76   108    >   INIT_FCALL                                               'printf'
        109        SEND_VAL                                                 '%3Ctr%3E%3Ctd%3E%25s%3C%2Ftd%3E%3Ctd%3E%E3%80%80%3C%2Ftd%3E%3Ctd%3E%25s%3C%2Ftd%3E%3C%2Ftr%3E'
        110        SEND_VAR                                                 !3
        111        SEND_VAR                                                 !4
        112        DO_ICALL                                                 
   75   113      > JMP                                                      ->107
        114    >   FE_FREE                                                  $68
   79   115        ECHO                                                     '%3C%2Ftable%3E%0A'
        116      > JMP                                                      ->118
   84   117    >   ECHO                                                     '%E7%B5%90%E6%9E%9C%E3%81%8C%E3%81%BE%E3%81%A0%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%0A'
   89   118    >   ECHO                                                     '%3C%2Ffieldset%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   91   119      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.11 ms | 1412 KiB | 25 Q