3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MineSweeper{ private $data = NULL; private $map; function debug(){ header('Content-Type:text/plain'); } function createMap($data){ $this->data = $data; if(!preg_match('/^[\*\.\r\n]+$/', $this->data)){ throw new Exception('Invalid input provided. Only asterik (*) and/or dot (.) is allowed.'); } // breaking input to lines $lines = preg_split('/\r\n/', $this->data); $tmp_line = NULL; // holding previous line for comparsion // lines index foreach ($lines as $lnum=>$line){ // lines should be equal in length if ($tmp_line != NULL && strlen($tmp_line) != strlen($line) ){ throw new Exception('Invalid input provided, please correct the format. Not all rows are equal.'); }else { $tmp_line = $line; // removing back spac and line break and spliting into charatcers (means multi dimension array) $lines[$lnum] = str_split(str_replace('\r\n','', $line)); } } // N= lines // M = Characters $M = count($lines[0]); $this->map = new MineMap($lines); } function display(){ $this->map->display(); } } class MineMap{ private $lines = array(); private $N; private $M; function __construct($lines){ $this->lines = $lines; $this->N = count($lines); $this->M = count($lines[0]); foreach($this->lines as $lnum => $line){ $this->lines[$lnum] = array_map(function($str){ return (trim($str) == "*") ? trim($str) : 0; }, $line); } foreach($this->lines as $lnum => $line){ foreach($line as $index => $str){ if ($str === "*"){ $this->mineFound($lnum, $index); } } } } function incValue($n, $m){ if ($m < $this->M && $n < $this->N && $n >= 0 && $m >= 0){ $this->lines[$n][$m]++; } } function mineFound($n, $m){ $this->incValue($n, $m+1); $this->incValue($n, $m-1); $this->incValue($n+1, $m-1); $this->incValue($n+1, $m); $this->incValue($n+1, $m+1); $this->incValue($n-1, $m-1); $this->incValue($n-1, $m); $this->incValue($n-1, $m+1); } function display(){ echo "<table cellspacin='5px'>"; foreach ($this->lines as $line){ echo "<tr>"; foreach($line as $str){ echo "<td style=''><button data='$str' class='btn btn-primary'>&nbsp;&nbsp;&nbsp;</td>"; } echo "</tr>"; } echo "</table>"; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Re39j
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FRe39j%3A66%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Re39j
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   67     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        IS_EQUAL                                                 $1, '%2A'
          5      > JMPZ                                                     ~2, ->11
          6    >   INIT_FCALL                                               'trim'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $3      
          9        QM_ASSIGN                                        ~4      $3
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~4      0
         12    > > RETURN                                                   ~4
   68    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRe39j%3A66%240

Class MineSweeper:
Function debug:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Re39j
function name:  debug
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-Type%3Atext%2Fplain'
          2        DO_ICALL                                                 
   12     3      > RETURN                                                   null

End of function debug

Function createmap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 48
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 48
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 30
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/Re39j
function name:  createMap
number of ops:  58
compiled vars:  !0 = $data, !1 = $lines, !2 = $tmp_line, !3 = $line, !4 = $lnum, !5 = $M
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   18     3        INIT_FCALL                                               'preg_match'
          4        SEND_VAL                                                 '%2F%5E%5B%5C%2A%5C.%5Cr%5Cn%5D%2B%24%2F'
          5        FETCH_OBJ_R                                      ~7      'data'
          6        SEND_VAL                                                 ~7
          7        DO_ICALL                                         $8      
          8        BOOL_NOT                                         ~9      $8
          9      > JMPZ                                                     ~9, ->14
   19    10    >   NEW                                              $10     'Exception'
         11        SEND_VAL_EX                                              'Invalid+input+provided.+Only+asterik+%28%2A%29+and%2For+dot+%28.%29+is+allowed.'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $10
   23    14    >   INIT_FCALL                                               'preg_split'
         15        SEND_VAL                                                 '%2F%5Cr%5Cn%2F'
         16        FETCH_OBJ_R                                      ~12     'data'
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !1, $13
   25    20        ASSIGN                                                   !2, null
   27    21      > FE_RESET_R                                       $16     !1, ->48
         22    > > FE_FETCH_R                                       ~17     $16, !3, ->48
         23    >   ASSIGN                                                   !4, ~17
   29    24        IS_NOT_EQUAL                                     ~19     !2, null
         25      > JMPZ_EX                                          ~19     ~19, ->30
         26    >   STRLEN                                           ~20     !2
         27        STRLEN                                           ~21     !3
         28        IS_NOT_EQUAL                                     ~22     ~20, ~21
         29        BOOL                                             ~19     ~22
         30    > > JMPZ                                                     ~19, ->36
   30    31    >   NEW                                              $23     'Exception'
         32        SEND_VAL_EX                                              'Invalid+input+provided%2C+please+correct+the+format.+Not+all+rows+are+equal.'
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $23
         35*       JMP                                                      ->47
   32    36    >   ASSIGN                                                   !2, !3
   34    37        INIT_FCALL                                               'str_split'
         38        INIT_FCALL                                               'str_replace'
         39        SEND_VAL                                                 '%5Cr%5Cn'
         40        SEND_VAL                                                 ''
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $27     
         43        SEND_VAR                                                 $27
         44        DO_ICALL                                         $28     
         45        ASSIGN_DIM                                               !1, !4
         46        OP_DATA                                                  $28
   27    47      > JMP                                                      ->22
         48    >   FE_FREE                                                  $16
   40    49        FETCH_DIM_R                                      ~29     !1, 0
         50        COUNT                                            ~30     ~29
         51        ASSIGN                                                   !5, ~30
   42    52        NEW                                              $33     'MineMap'
         53        SEND_VAR_EX                                              !1
         54        DO_FCALL                                      0          
         55        ASSIGN_OBJ                                               'map'
         56        OP_DATA                                                  $33
   43    57      > RETURN                                                   null

End of function createmap

Function display:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Re39j
function name:  display
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   FETCH_OBJ_R                                      ~0      'map'
          1        INIT_METHOD_CALL                                         ~0, 'display'
          2        DO_FCALL                                      0          
   47     3      > RETURN                                                   null

End of function display

End of class MineSweeper.

Class MineMap:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 40
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 40
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 38
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 38
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 38
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 23
filename:       /in/Re39j
function name:  __construct
number of ops:  42
compiled vars:  !0 = $lines, !1 = $line, !2 = $lnum, !3 = $str, !4 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   60     1        ASSIGN_OBJ                                               'lines'
          2        OP_DATA                                                  !0
   62     3        COUNT                                            ~7      !0
          4        ASSIGN_OBJ                                               'N'
          5        OP_DATA                                                  ~7
   63     6        FETCH_DIM_R                                      ~9      !0, 0
          7        COUNT                                            ~10     ~9
          8        ASSIGN_OBJ                                               'M'
          9        OP_DATA                                                  ~10
   65    10        FETCH_OBJ_R                                      ~11     'lines'
         11      > FE_RESET_R                                       $12     ~11, ->23
         12    > > FE_FETCH_R                                       ~13     $12, !1, ->23
         13    >   ASSIGN                                                   !2, ~13
   66    14        INIT_FCALL                                               'array_map'
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRe39j%3A66%240'
   68    16        SEND_VAL                                                 ~17
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $18     
   66    19        FETCH_OBJ_W                                      $15     'lines'
         20        ASSIGN_DIM                                               $15, !2
   68    21        OP_DATA                                                  $18
   65    22      > JMP                                                      ->12
         23    >   FE_FREE                                                  $12
   71    24        FETCH_OBJ_R                                      ~19     'lines'
         25      > FE_RESET_R                                       $20     ~19, ->40
         26    > > FE_FETCH_R                                       ~21     $20, !1, ->40
         27    >   ASSIGN                                                   !2, ~21
   72    28      > FE_RESET_R                                       $23     !1, ->38
         29    > > FE_FETCH_R                                       ~24     $23, !3, ->38
         30    >   ASSIGN                                                   !4, ~24
   73    31        IS_IDENTICAL                                             !3, '%2A'
         32      > JMPZ                                                     ~26, ->37
   74    33    >   INIT_METHOD_CALL                                         'mineFound'
         34        SEND_VAR_EX                                              !2
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
   72    37    > > JMP                                                      ->29
         38    >   FE_FREE                                                  $23
   71    39      > JMP                                                      ->26
         40    >   FE_FREE                                                  $20
   78    41      > RETURN                                                   null

End of function __construct

Function incvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/Re39j
function name:  incValue
number of ops:  20
compiled vars:  !0 = $n, !1 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   81     2        FETCH_OBJ_R                                      ~2      'M'
          3        IS_SMALLER                                       ~3      !1, ~2
          4      > JMPZ_EX                                          ~3      ~3, ->8
          5    >   FETCH_OBJ_R                                      ~4      'N'
          6        IS_SMALLER                                       ~5      !0, ~4
          7        BOOL                                             ~3      ~5
          8    > > JMPZ_EX                                          ~3      ~3, ->11
          9    >   IS_SMALLER_OR_EQUAL                              ~6      0, !0
         10        BOOL                                             ~3      ~6
         11    > > JMPZ_EX                                          ~3      ~3, ->14
         12    >   IS_SMALLER_OR_EQUAL                              ~7      0, !1
         13        BOOL                                             ~3      ~7
         14    > > JMPZ                                                     ~3, ->19
   82    15    >   FETCH_OBJ_RW                                     $8      'lines'
         16        FETCH_DIM_RW                                     $9      $8, !0
         17        FETCH_DIM_RW                                     $10     $9, !1
         18        PRE_INC                                                  $10
   84    19    > > RETURN                                                   null

End of function incvalue

Function minefound:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Re39j
function name:  mineFound
number of ops:  47
compiled vars:  !0 = $n, !1 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   87     2        INIT_METHOD_CALL                                         'incValue'
          3        SEND_VAR_EX                                              !0
          4        ADD                                              ~2      !1, 1
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0          
   88     7        INIT_METHOD_CALL                                         'incValue'
          8        SEND_VAR_EX                                              !0
          9        SUB                                              ~4      !1, 1
         10        SEND_VAL_EX                                              ~4
         11        DO_FCALL                                      0          
   90    12        INIT_METHOD_CALL                                         'incValue'
         13        ADD                                              ~6      !0, 1
         14        SEND_VAL_EX                                              ~6
         15        SUB                                              ~7      !1, 1
         16        SEND_VAL_EX                                              ~7
         17        DO_FCALL                                      0          
   91    18        INIT_METHOD_CALL                                         'incValue'
         19        ADD                                              ~9      !0, 1
         20        SEND_VAL_EX                                              ~9
         21        SEND_VAR_EX                                              !1
         22        DO_FCALL                                      0          
   92    23        INIT_METHOD_CALL                                         'incValue'
         24        ADD                                              ~11     !0, 1
         25        SEND_VAL_EX                                              ~11
         26        ADD                                              ~12     !1, 1
         27        SEND_VAL_EX                                              ~12
         28        DO_FCALL                                      0          
   94    29        INIT_METHOD_CALL                                         'incValue'
         30        SUB                                              ~14     !0, 1
         31        SEND_VAL_EX                                              ~14
         32        SUB                                              ~15     !1, 1
         33        SEND_VAL_EX                                              ~15
         34        DO_FCALL                                      0          
   95    35        INIT_METHOD_CALL                                         'incValue'
         36        SUB                                              ~17     !0, 1
         37        SEND_VAL_EX                                              ~17
         38        SEND_VAR_EX                                              !1
         39        DO_FCALL                                      0          
   96    40        INIT_METHOD_CALL                                         'incValue'
         41        SUB                                              ~19     !0, 1
         42        SEND_VAL_EX                                              ~19
         43        ADD                                              ~20     !1, 1
         44        SEND_VAL_EX                                              ~20
         45        DO_FCALL                                      0          
   97    46      > RETURN                                                   null

End of function minefound

Function display:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/Re39j
function name:  display
number of ops:  18
compiled vars:  !0 = $line, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  100     0  E >   ECHO                                                     '%3Ctable+cellspacin%3D%275px%27%3E'
  101     1        FETCH_OBJ_R                                      ~2      'lines'
          2      > FE_RESET_R                                       $3      ~2, ->15
          3    > > FE_FETCH_R                                               $3, !0, ->15
  102     4    >   ECHO                                                     '%3Ctr%3E'
  103     5      > FE_RESET_R                                       $4      !0, ->12
          6    > > FE_FETCH_R                                               $4, !1, ->12
  104     7    >   ROPE_INIT                                     3  ~6      '%3Ctd+style%3D%27%27%3E%3Cbutton+data%3D%27'
          8        ROPE_ADD                                      1  ~6      ~6, !1
          9        ROPE_END                                      2  ~5      ~6, '%27+class%3D%27btn+btn-primary%27%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2Ftd%3E'
         10        ECHO                                                     ~5
  103    11      > JMP                                                      ->6
         12    >   FE_FREE                                                  $4
  106    13        ECHO                                                     '%3C%2Ftr%3E'
  101    14      > JMP                                                      ->3
         15    >   FE_FREE                                                  $3
  109    16        ECHO                                                     '%3C%2Ftable%3E'
  110    17      > RETURN                                                   null

End of function display

End of class MineMap.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.24 ms | 1420 KiB | 27 Q