3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CommentController extends AdminController { // 検証 function validateGet(string $class,string $function): mixed { $params = []; if($function === 'searchAction'){ // ★案A:コントローラ内に書く $orderBy = $_GET['orderBy'] ?? null; $oks = ['id','updatedAt']; if(in_array($orderBy,$oks,true)){ $params['orderBy'] = $orderBy; }else{ $params['orderBy'] = 'id'; } // ★汎用的な検証メソッドを使用 $uniqueId = $_GET['uniqueId'] ?? null; $validated = Validator::validateUniqueId($uniqueId); if ($validated) { // 検証失敗時はメッセージテキストが返るので, ここでそのまま返して終了 return $validated; } else { // 検証成功時はそのままセット $validatedParams['uniqueId'] = $uniqueId; } } return $params; } // 検索 function searchAction(): void { // 検証 $params = $this->validateGet(__CLASS__, __FUNCTION__); if(is_string($params)){ // エラーメッセージの文字列なら // スロー } $commentMapper = new CommentMapper(); $stmt = $commentMapper->find($params); $this->render([ 'data' => $stmt->fetchAll()->toAry() ]); } } class Validator { static function validateUniqueId(mixed $value): string { $pattern = '/^[0-9A-Za-z]{22}$/'; if (!(bool)preg_match($pattern, $value)) { return 'uniqueId is not valid.'; } return ''; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r3WMM
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'commentcontroller', 'admincontroller'
   61     1      > RETURN                                                   1

Class CommentController:
Function validateget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 36
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
Branch analysis from position: 34
Branch analysis from position: 36
filename:       /in/r3WMM
function name:  validateGet
number of ops:  39
compiled vars:  !0 = $class, !1 = $function, !2 = $params, !3 = $orderBy, !4 = $oks, !5 = $uniqueId, !6 = $validated, !7 = $validatedParams
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN                                                   !2, <array>
   10     3        IS_IDENTICAL                                             !1, 'searchAction'
          4      > JMPZ                                                     ~9, ->36
   12     5    >   FETCH_IS                                         ~10     '_GET'
          6        FETCH_DIM_IS                                     ~11     ~10, 'orderBy'
          7        COALESCE                                         ~12     ~11
          8        QM_ASSIGN                                        ~12     null
          9        ASSIGN                                                   !3, ~12
   13    10        ASSIGN                                                   !4, <array>
   14    11        INIT_FCALL                                               'in_array'
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !4
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $15     
         16      > JMPZ                                                     $15, ->20
   15    17    >   ASSIGN_DIM                                               !2, 'orderBy'
         18        OP_DATA                                                  !3
   14    19      > JMP                                                      ->22
   17    20    >   ASSIGN_DIM                                               !2, 'orderBy'
         21        OP_DATA                                                  'id'
   21    22    >   FETCH_IS                                         ~18     '_GET'
         23        FETCH_DIM_IS                                     ~19     ~18, 'uniqueId'
         24        COALESCE                                         ~20     ~19
         25        QM_ASSIGN                                        ~20     null
         26        ASSIGN                                                   !5, ~20
   22    27        INIT_STATIC_METHOD_CALL                                  'Validator', 'validateUniqueId'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0  $22     
         30        ASSIGN                                                   !6, $22
   23    31      > JMPZ                                                     !6, ->34
   24    32    > > RETURN                                                   !6
   23    33*       JMP                                                      ->36
   26    34    >   ASSIGN_DIM                                               !7, 'uniqueId'
         35        OP_DATA                                                  !5
   30    36    > > RETURN                                                   !2
   31    37*       VERIFY_RETURN_TYPE                                       
         38*     > RETURN                                                   null

End of function validateget

Function searchaction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/r3WMM
function name:  searchAction
number of ops:  23
compiled vars:  !0 = $params, !1 = $commentMapper, !2 = $stmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_METHOD_CALL                                         'validateGet'
          1        SEND_VAL_EX                                              'CommentController'
          2        SEND_VAL_EX                                              'searchAction'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   38     5        TYPE_CHECK                                   64          !0
          6      > JMPZ                                                     ~5, ->7
   42     7    >   NEW                                              $6      'CommentMapper'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $6
   43    10        INIT_METHOD_CALL                                         !1, 'find'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !2, $9
   45    14        INIT_METHOD_CALL                                         'render'
   46    15        INIT_METHOD_CALL                                         !2, 'fetchAll'
         16        DO_FCALL                                      0  $11     
         17        INIT_METHOD_CALL                                         $11, 'toAry'
         18        DO_FCALL                                      0  $12     
         19        INIT_ARRAY                                       ~13     $12, 'data'
         20        SEND_VAL_EX                                              ~13
   45    21        DO_FCALL                                      0          
   48    22      > RETURN                                                   null

End of function searchaction

End of class CommentController.

Class Validator:
Function validateuniqueid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r3WMM
function name:  validateUniqueId
number of ops:  13
compiled vars:  !0 = $value, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        ASSIGN                                                   !1, '%2F%5E%5B0-9A-Za-z%5D%7B22%7D%24%2F'
   56     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        BOOL                                             ~4      $3
          7        BOOL_NOT                                         ~5      ~4
          8      > JMPZ                                                     ~5, ->10
   57     9    > > RETURN                                                   'uniqueId+is+not+valid.'
   59    10    > > RETURN                                                   ''
   60    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function validateuniqueid

End of class Validator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.93 ms | 1015 KiB | 15 Q