3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Janken; use Closure; const WIN_LOSE_TABLE = [ 'グー' => ['チョキ' => 1, 'パー' => -1], 'チョキ' => ['パー' => 1, 'グー' => -1], 'パー' => ['グー' => 1, 'チョキ' => -1], ]; const EMOJI_TABLE = [ 'グー' => '✊', 'チョキ' => '✌', 'パー' => '🖐', ]; $printer = fn(string $my_hand, string $your_hand, int $result): string => sprintf("[%s vs %s] %s", EMOJI_TABLE[$my_hand], EMOJI_TABLE[$your_hand], match ($result) { -1 => 'あなたの負け', 0 => 'あいこ', 1 => 'あなたの勝ち', } ); foreach (['グー', 'チョキ', 'パー'] as $my_hand) { foreach (['グー', 'チョキ', 'パー'] as $your_hand) { echo battle($my_hand, $your_hand, $printer), PHP_EOL; } } function battle(string $my_hand, string $your_hand, Closure $printer): string { return $printer($my_hand, $your_hand, WIN_LOSE_TABLE[$my_hand][$your_hand] ?? 0); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/MFqsQ
function name:  (null)
number of ops:  21
compiled vars:  !0 = $printer, !1 = $my_hand, !2 = $your_hand
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CONST                                            'Janken%5CWIN_LOSE_TABLE', <array>
   13     1        DECLARE_CONST                                            'Janken%5CEMOJI_TABLE', <array>
   19     2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          3        ASSIGN                                                   !0, ~3
   30     4      > FE_RESET_R                                       $5      <array>, ->19
          5    > > FE_FETCH_R                                               $5, !1, ->19
   31     6    > > FE_RESET_R                                       $6      <array>, ->17
          7    > > FE_FETCH_R                                               $6, !2, ->17
   32     8    >   INIT_NS_FCALL_BY_NAME                                    'Janken%5Cbattle'
          9        SEND_VAR_EX                                              !1
         10        SEND_VAR_EX                                              !2
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
         14        FETCH_CONSTANT                                   ~8      'Janken%5CPHP_EOL'
         15        ECHO                                                     ~8
   31    16      > JMP                                                      ->7
         17    >   FE_FREE                                                  $6
   30    18      > JMP                                                      ->5
         19    >   FE_FREE                                                  $5
   39    20      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 195) Position 1 = 15, Position 2 = 17, Position 3 = 19, Position 4 = 14
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 14
1 jumps found. (Code = 197) Position 1 = -2
filename:       /in/MFqsQ
function name:  Janken\{closure}
number of ops:  27
compiled vars:  !0 = $my_hand, !1 = $your_hand, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   20     3        INIT_NS_FCALL_BY_NAME                                    'Janken%5Csprintf'
          4        SEND_VAL_EX                                              '%5B%25s+vs+%25s%5D+%25s'
          5        CHECK_FUNC_ARG                                           
   21     6        FETCH_CONSTANT                                   ~3      'Janken%5CEMOJI_TABLE'
          7        FETCH_DIM_FUNC_ARG                               $4      ~3, !0
          8        SEND_FUNC_ARG                                            $4
          9        CHECK_FUNC_ARG                                           
   22    10        FETCH_CONSTANT                                   ~5      'Janken%5CEMOJI_TABLE'
         11        FETCH_DIM_FUNC_ARG                               $6      ~5, !1
         12        SEND_FUNC_ARG                                            $6
   23    13      > MATCH                                                    !2, [ -1:->15, 0:->17, 1:->19, ], ->14
         14    > > MATCH_ERROR                                              !2
   24    15    >   QM_ASSIGN                                        ~8      '%E3%81%82%E3%81%AA%E3%81%9F%E3%81%AE%E8%B2%A0%E3%81%91'
         16      > JMP                                                      ->21
   25    17    >   QM_ASSIGN                                        ~8      '%E3%81%82%E3%81%84%E3%81%93'
         18      > JMP                                                      ->21
   26    19    >   QM_ASSIGN                                        ~8      '%E3%81%82%E3%81%AA%E3%81%9F%E3%81%AE%E5%8B%9D%E3%81%A1'
         20      > JMP                                                      ->21
         21    >   SEND_VAL_EX                                              ~8
   20    22        DO_FCALL                                      0  $9      
   26    23        VERIFY_RETURN_TYPE                                       $9
         24      > RETURN                                                   $9
   28    25*       VERIFY_RETURN_TYPE                                       
         26*     > RETURN                                                   null

End of Dynamic Function 0

Function janken%5Cbattle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MFqsQ
function name:  Janken\battle
number of ops:  17
compiled vars:  !0 = $my_hand, !1 = $your_hand, !2 = $printer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   38     3        INIT_DYNAMIC_CALL                                        !2
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        FETCH_CONSTANT                                   ~3      'Janken%5CWIN_LOSE_TABLE'
          7        FETCH_DIM_IS                                     ~4      ~3, !0
          8        FETCH_DIM_IS                                     ~5      ~4, !1
          9        COALESCE                                         ~6      ~5
         10        QM_ASSIGN                                        ~6      0
         11        SEND_VAL_EX                                              ~6
         12        DO_FCALL                                      0  $7      
         13        VERIFY_RETURN_TYPE                                       $7
         14      > RETURN                                                   $7
   39    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function janken%5Cbattle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.3 ms | 1005 KiB | 15 Q