3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 1件のコメントをINSERTする function insert_comment_single( $comment, $is_table_lock ){ try { $dbh = db_open(); if ( $is_table_lock ) { // テーブルロックを実行 $sql = 'LOCK TABLES tbl_comments WRITE, tbl_relations WRITE, tbl_tags WRITE'; $db->query( $sql ); } // INSERTする $sql = 'INSERT ...'; $db->query( $sql ); // エラー確認 if ( 何かエラーなら ) throw new Exception('何かエラーです'); // エラーなければコミット if ( $is_table_lock ) $dbh->commit(); // 戻り値 $result = [ 'status' => 'ok', 'inserted_id' => 1 ]; } catch (Exception $e) { // エラーならロールバック if ( $is_table_lock ) $dbh->rollback(); // 戻り値 $result = [ 'status' => 'error', 'message' => $e->getMessage() ]; } return $result; } // 複数のコメントをINSERTする function insert_comment_multiple( $comment_arr, $is_table_lock ){ try { $dbh = db_open(); if ( $is_table_lock ) { // テーブルロックを実行 $sql = 'LOCK TABLES tbl_comments WRITE, tbl_relations WRITE, tbl_tags WRITE'; $db->query($sql); // 当関数でロックしたので single の方ではロックしない $is_table_lock2 = false; } // ループ結果 $inserted_arr = []; // single の結果 $error_index_arr = []; // エラー番号 // ループで single を実行してINSERTする foreach( $comment_arr as $index => $comment ){ $inserted = insert_comment_single( $comment, $is_table_lock2 ); // エラー番号をセット if ( $inserted['status'] === 'error' ) $error_index_arr[] = $index; // single の結果をセット $inserted_arr[] = $inserted; } // 当関数でテーブルロックした場合、1件でもエラーのときは throw でロールバック if ( $is_table_lock && !empty($error_index_arr) ) throw new Exception( implode(',',$error_index_arr) . 'でエラー'); // エラーなければコミット if ( $is_table_lock ) $dbh->commit(); // 戻り値 $result = [ 'status' =>'ok', 'inserted_arr' => $inserted_arr ]; // 当関数でテーブルロックしない場合、エラー番号を入れる if ( !$is_table_lock && !empty($error_index_arr) ) $result['error_index_arr'] = $error_index_arr; } catch (Exception $e) { // エラーならロールバック if ( $is_table_lock ) $dbh->rollback(); // 戻り値 $result = [ 'status' => 'error', 'inserted_arr' => $inserted_arr, 'message' => $e->getMessage() ]; } return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7Zhta
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E > > RETURN                                                   1

Function insert_comment_single:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 10
Found catch point at position: 25
Branch analysis from position: 25
2 jumps found. (Code = 107) Position 1 = 26, Position 2 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/7Zhta
function name:  insert_comment_single
number of ops:  36
compiled vars:  !0 = $comment, !1 = $is_table_lock, !2 = $dbh, !3 = $sql, !4 = $db, !5 = $result, !6 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL_BY_NAME                                       'db_open'
          3        DO_FCALL                                      0  $7      
          4        ASSIGN                                                   !2, $7
    9     5      > JMPZ                                                     !1, ->10
   11     6    >   ASSIGN                                                   !3, 'LOCK+TABLES+tbl_comments+WRITE%2C+tbl_relations+WRITE%2C+tbl_tags+WRITE'
   12     7        INIT_METHOD_CALL                                         !4, 'query'
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0          
   16    10    >   ASSIGN                                                   !3, 'INSERT+...'
   17    11        INIT_METHOD_CALL                                         !4, 'query'
         12        SEND_VAR_EX                                              !3
         13        DO_FCALL                                      0          
   20    14        FETCH_CONSTANT                                   ~13     '%E4%BD%95%E3%81%8B%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%AA%E3%82%89'
         15      > JMPZ                                                     ~13, ->20
   21    16    >   NEW                                              $14     'Exception'
         17        SEND_VAL_EX                                              '%E4%BD%95%E3%81%8B%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%A7%E3%81%99'
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $14
   24    20    > > JMPZ                                                     !1, ->23
   25    21    >   INIT_METHOD_CALL                                         !2, 'commit'
         22        DO_FCALL                                      0          
   28    23    >   ASSIGN                                                   !5, <array>
         24      > JMP                                                      ->34
   33    25  E > > CATCH                                       last         'Exception'
   36    26    > > JMPZ                                                     !1, ->29
   37    27    >   INIT_METHOD_CALL                                         !2, 'rollback'
         28        DO_FCALL                                      0          
   41    29    >   INIT_ARRAY                                       ~19     'error', 'status'
   42    30        INIT_METHOD_CALL                                         !6, 'getMessage'
         31        DO_FCALL                                      0  $20     
         32        ADD_ARRAY_ELEMENT                                ~19     $20, 'message'
   40    33        ASSIGN                                                   !5, ~19
   46    34    > > RETURN                                                   !5
   47    35*     > RETURN                                                   null

End of function insert_comment_single

Function insert_comment_multiple:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 44
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 55
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 55
Branch analysis from position: 47
Branch analysis from position: 34
Branch analysis from position: 29
Branch analysis from position: 11
Found catch point at position: 59
Branch analysis from position: 59
2 jumps found. (Code = 107) Position 1 = 60, Position 2 = -2
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
filename:       /in/7Zhta
function name:  insert_comment_multiple
number of ops:  71
compiled vars:  !0 = $comment_arr, !1 = $is_table_lock, !2 = $dbh, !3 = $sql, !4 = $db, !5 = $is_table_lock2, !6 = $inserted_arr, !7 = $error_index_arr, !8 = $comment, !9 = $index, !10 = $inserted, !11 = $result, !12 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        INIT_FCALL_BY_NAME                                       'db_open'
          3        DO_FCALL                                      0  $13     
          4        ASSIGN                                                   !2, $13
   56     5      > JMPZ                                                     !1, ->11
   58     6    >   ASSIGN                                                   !3, 'LOCK+TABLES+tbl_comments+WRITE%2C+tbl_relations+WRITE%2C+tbl_tags+WRITE'
   59     7        INIT_METHOD_CALL                                         !4, 'query'
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0          
   62    10        ASSIGN                                                   !5, <false>
   66    11    >   ASSIGN                                                   !6, <array>
   67    12        ASSIGN                                                   !7, <array>
   70    13      > FE_RESET_R                                       $20     !0, ->29
         14    > > FE_FETCH_R                                       ~21     $20, !8, ->29
         15    >   ASSIGN                                                   !9, ~21
   71    16        INIT_FCALL                                               'insert_comment_single'
         17        SEND_VAR                                                 !8
         18        SEND_VAR                                                 !5
         19        DO_FCALL                                      0  $23     
         20        ASSIGN                                                   !10, $23
   74    21        FETCH_DIM_R                                      ~25     !10, 'status'
         22        IS_IDENTICAL                                             ~25, 'error'
         23      > JMPZ                                                     ~26, ->26
   75    24    >   ASSIGN_DIM                                               !7
         25        OP_DATA                                                  !9
   78    26    >   ASSIGN_DIM                                               !6
         27        OP_DATA                                                  !10
   70    28      > JMP                                                      ->14
         29    >   FE_FREE                                                  $20
   82    30      > JMPZ_EX                                          ~29     !1, ->34
         31    >   ISSET_ISEMPTY_CV                                 ~30     !7
         32        BOOL_NOT                                         ~31     ~30
         33        BOOL                                             ~29     ~31
         34    > > JMPZ                                                     ~29, ->44
   83    35    >   NEW                                              $32     'Exception'
         36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%2C'
         38        SEND_VAR                                                 !7
         39        DO_ICALL                                         $33     
         40        CONCAT                                           ~34     $33, '%E3%81%A7%E3%82%A8%E3%83%A9%E3%83%BC'
         41        SEND_VAL_EX                                              ~34
         42        DO_FCALL                                      0          
         43      > THROW                                         0          $32
   86    44    > > JMPZ                                                     !1, ->47
   87    45    >   INIT_METHOD_CALL                                         !2, 'commit'
         46        DO_FCALL                                      0          
   91    47    >   INIT_ARRAY                                       ~37     'ok', 'status'
   92    48        ADD_ARRAY_ELEMENT                                ~37     !6, 'inserted_arr'
   90    49        ASSIGN                                                   !11, ~37
   96    50        BOOL_NOT                                         ~39     !1
         51      > JMPZ_EX                                          ~39     ~39, ->55
         52    >   ISSET_ISEMPTY_CV                                 ~40     !7
         53        BOOL_NOT                                         ~41     ~40
         54        BOOL                                             ~39     ~41
         55    > > JMPZ                                                     ~39, ->58
   97    56    >   ASSIGN_DIM                                               !11, 'error_index_arr'
         57        OP_DATA                                                  !7
         58    > > JMP                                                      ->69
   99    59  E > > CATCH                                       last         'Exception'
  102    60    > > JMPZ                                                     !1, ->63
  103    61    >   INIT_METHOD_CALL                                         !2, 'rollback'
         62        DO_FCALL                                      0          
  107    63    >   INIT_ARRAY                                       ~44     'error', 'status'
  108    64        ADD_ARRAY_ELEMENT                                ~44     !6, 'inserted_arr'
  109    65        INIT_METHOD_CALL                                         !12, 'getMessage'
         66        DO_FCALL                                      0  $45     
         67        ADD_ARRAY_ELEMENT                                ~44     $45, 'message'
  106    68        ASSIGN                                                   !11, ~44
  113    69    > > RETURN                                                   !11
  114    70*     > RETURN                                                   null

End of function insert_comment_multiple

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.45 ms | 1025 KiB | 15 Q