3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dataFormat = array( "dateTimeOfData" => "DateTime", "open" => "double", "high" => "double", "low" => "double", "close" => "double", "volume" => "integer", "isCritical" => "boolean"//Temporary ); function validateFormat($data){ global $dataFormat; //Check that all the required fields exist $missing = array_diff_key($dataFormat, $data); $extra = array_diff_key($data, $dataFormat); if(!empty($missing) || !empty($extra)){ throw new InvalidArgumentException("Incorrect data format provided"); } //Check that all the data is of the correct type foreach($data as $k => $v){ $type = gettype($v) === "object" ? get_class($v) : gettype($v); $correctType = $dataFormat[$k]; if($type !== $correctType){ throw new InvalidArgumentException("Data is of an incorrect type."); } } } $arr = array("dateTimeOfData" => new DateTime(), //"open" => 10.1, "high" => 10.1, "low" => 10.1, "close" => 10.1, "volume" => 10, "isCritical" => true); validateFormat($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Umaef
function name:  (null)
number of ops:  14
compiled vars:  !0 = $dataFormat, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        NEW                                              $3      'DateTime'
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~5      $3, 'dateTimeOfData'
   32     4        ADD_ARRAY_ELEMENT                                ~5      10.1, 'high'
   33     5        ADD_ARRAY_ELEMENT                                ~5      10.1, 'low'
   34     6        ADD_ARRAY_ELEMENT                                ~5      10.1, 'close'
   35     7        ADD_ARRAY_ELEMENT                                ~5      10, 'volume'
   30     8        ADD_ARRAY_ELEMENT                                ~5      <true>, 'isCritical'
          9        ASSIGN                                                   !1, ~5
   37    10        INIT_FCALL                                               'validateformat'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Function validateformat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 44
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 44
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
Branch analysis from position: 43
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 18
filename:       /in/Umaef
function name:  validateFormat
number of ops:  46
compiled vars:  !0 = $data, !1 = $dataFormat, !2 = $missing, !3 = $extra, !4 = $v, !5 = $k, !6 = $type, !7 = $correctType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        BIND_GLOBAL                                              !1, 'dataFormat'
   16     2        INIT_FCALL                                               'array_diff_key'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
   17     7        INIT_FCALL                                               'array_diff_key'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !3, $10
   18    12        ISSET_ISEMPTY_CV                                 ~12     !2
         13        BOOL_NOT                                         ~13     ~12
         14      > JMPNZ_EX                                         ~13     ~13, ->18
         15    >   ISSET_ISEMPTY_CV                                 ~14     !3
         16        BOOL_NOT                                         ~15     ~14
         17        BOOL                                             ~13     ~15
         18    > > JMPZ                                                     ~13, ->23
   19    19    >   NEW                                              $16     'InvalidArgumentException'
         20        SEND_VAL_EX                                              'Incorrect+data+format+provided'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $16
   22    23    > > FE_RESET_R                                       $18     !0, ->44
         24    > > FE_FETCH_R                                       ~19     $18, !4, ->44
         25    >   ASSIGN                                                   !5, ~19
   23    26        GET_TYPE                                         ~21     !4
         27        IS_IDENTICAL                                             ~21, 'object'
         28      > JMPZ                                                     ~22, ->32
         29    >   GET_CLASS                                        ~23     !4
         30        QM_ASSIGN                                        ~24     ~23
         31      > JMP                                                      ->34
         32    >   GET_TYPE                                         ~25     !4
         33        QM_ASSIGN                                        ~24     ~25
         34    >   ASSIGN                                                   !6, ~24
   24    35        FETCH_DIM_R                                      ~27     !1, !5
         36        ASSIGN                                                   !7, ~27
   25    37        IS_NOT_IDENTICAL                                         !6, !7
         38      > JMPZ                                                     ~29, ->43
   26    39    >   NEW                                              $30     'InvalidArgumentException'
         40        SEND_VAL_EX                                              'Data+is+of+an+incorrect+type.'
         41        DO_FCALL                                      0          
         42      > THROW                                         0          $30
   22    43    > > JMP                                                      ->24
         44    >   FE_FREE                                                  $18
   29    45      > RETURN                                                   null

End of function validateformat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.62 ms | 1403 KiB | 16 Q