3v4l.org

run code in 300+ PHP versions simultaneously
<?php function accept_int(int $value) { return $value; } function accept_float(float $value) { return $value; } function accept_string(string $value) { return $value; } function accept_bool(bool $value) { return $value; } $scalarTypes = ['int', 'float', 'string', 'bool']; $data = [ 'int' => 1, 'int-negative' => -1, 'int-zero' => 0, 'float' => 1.2, 'float-negative' => -1.2, 'float-int' => 1.0, 'float-zero' => 0.0, 'string' => 'abc', 'string-empty' => '', 'string-space' => ' ', 'string-int' => '1', 'string-int-negative' => '-1', 'string-int-zero' => '0', 'string-int-spacepad' => ' 1', 'string-int-start' => '1abc', 'string-int-start-spacepad' => ' 1abc', 'string-float' => '1.2', 'string-float-negative' => '-1.2', 'string-float-int' => '1.0', 'string-float-zero' => '0.0', 'string-float-spacepad' => ' 1.2', 'string-float-spacepad-negative' => ' -1.2', 'string-float-start' => '1.2abc', 'string-float-start-negative' => '-1.2abc', 'string-float-start-spacepad' => ' 1.2abc', 'string-float-start-spacepad-negative' => ' -1.2abc', 'bool-true' => true, 'bool-false' => false, ]; function printValue($value) { if (is_string($value)) { return "\"$value\""; } if (is_bool($value)) { return $value ? 'true' : 'false'; } if (is_float($value)) { return number_format($value, 1); } return $value; } $resultsTable = []; foreach ($scalarTypes as $type) { foreach ($data as $key => $value) { $lineKey = $key . ': ' . printValue($value); $acceptFunction = "accept_$type"; try { $deprecatedFlag = false; $noticeFlag = false; set_error_handler(function (int $errno, string $errstr) use (&$deprecatedFlag, &$noticeFlag) { if ($errno === E_NOTICE) { $noticeFlag = true; } else { $deprecatedFlag = true; } echo $errstr . "\n"; }, E_DEPRECATED | E_NOTICE); $result = $acceptFunction($value); set_error_handler(null); if ($result === $value) { $op = 'ok'; } else { $op = 'coerced to ' . printValue($result); if ($deprecatedFlag) { $op .= ' (D)'; } if ($noticeFlag) { $op .= ' (N)'; } } } catch (Throwable $e) { $op = 'error'; } if (!isset($resultsTable[$lineKey])) { $resultsTable[$lineKey] = []; } $resultsTable[$lineKey][$type] = "$op"; } } echo "\n\nResults table:\n\n"; echo ' | ' . str_pad('data type: data', 50, ' ', STR_PAD_LEFT) . ' | '; foreach ($scalarTypes as $type) { echo str_pad($type, 20) . ' | '; } echo "\n"; echo ' | ' . str_pad('', 50, '-') . ' | '; foreach ($scalarTypes as $type) { echo str_pad('', 20, '-') . ' | '; } echo "\n"; foreach ($resultsTable as $key => $results) { echo ' | ' . str_pad($key, 50, ' ', STR_PAD_LEFT) . ' | '; foreach ($results as $type => $result) { echo str_pad($result, 20) . ' | '; } echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 61
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 61
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 59
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 59
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 54
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 46
Branch analysis from position: 44
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 59
Branch analysis from position: 61
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 81
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 81
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 81
2 jumps found. (Code = 77) Position 1 = 92, Position 2 = 101
Branch analysis from position: 92
2 jumps found. (Code = 78) Position 1 = 93, Position 2 = 101
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
Branch analysis from position: 101
2 jumps found. (Code = 77) Position 1 = 104, Position 2 = 128
Branch analysis from position: 104
2 jumps found. (Code = 78) Position 1 = 105, Position 2 = 128
Branch analysis from position: 105
2 jumps found. (Code = 77) Position 1 = 116, Position 2 = 125
Branch analysis from position: 116
2 jumps found. (Code = 78) Position 1 = 117, Position 2 = 125
Branch analysis from position: 117
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
Branch analysis from position: 125
Branch analysis from position: 128
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 128
Branch analysis from position: 101
Branch analysis from position: 81
Branch analysis from position: 61
Found catch point at position: 47
Branch analysis from position: 47
2 jumps found. (Code = 107) Position 1 = 48, Position 2 = -2
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
Branch analysis from position: 54
filename:       /in/hmHsT
function name:  (null)
number of ops:  130
compiled vars:  !0 = $scalarTypes, !1 = $data, !2 = $resultsTable, !3 = $type, !4 = $value, !5 = $key, !6 = $lineKey, !7 = $acceptFunction, !8 = $deprecatedFlag, !9 = $noticeFlag, !10 = $result, !11 = $op, !12 = $e, !13 = $results
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   64     2        ASSIGN                                                   !2, <array>
   65     3      > FE_RESET_R                                       $17     !0, ->61
          4    > > FE_FETCH_R                                               $17, !3, ->61
   66     5    > > FE_RESET_R                                       $18     !1, ->59
          6    > > FE_FETCH_R                                       ~19     $18, !4, ->59
          7    >   ASSIGN                                                   !5, ~19
   67     8        CONCAT                                           ~21     !5, '%3A+'
          9        INIT_FCALL                                               'printvalue'
         10        SEND_VAR                                                 !4
         11        DO_FCALL                                      0  $22     
         12        CONCAT                                           ~23     ~21, $22
         13        ASSIGN                                                   !6, ~23
   69    14        NOP                                                      
         15        FAST_CONCAT                                      ~25     'accept_', !3
         16        ASSIGN                                                   !7, ~25
   71    17        ASSIGN                                                   !8, <false>
   72    18        ASSIGN                                                   !9, <false>
   73    19        INIT_FCALL                                               'set_error_handler'
         20        DECLARE_LAMBDA_FUNCTION                          ~29     [0]
         21        BIND_LEXICAL                                             ~29, !8
         22        BIND_LEXICAL                                             ~29, !9
   80    23        SEND_VAL                                                 ~29
         24        SEND_VAL                                                 8200
   73    25        DO_ICALL                                                 
   81    26        INIT_DYNAMIC_CALL                                        !7
         27        SEND_VAR_EX                                              !4
         28        DO_FCALL                                      0  $31     
         29        ASSIGN                                                   !10, $31
   82    30        INIT_FCALL                                               'set_error_handler'
         31        SEND_VAL                                                 null
         32        DO_ICALL                                                 
   83    33        IS_IDENTICAL                                             !10, !4
         34      > JMPZ                                                     ~34, ->37
   84    35    >   ASSIGN                                                   !11, 'ok'
   83    36      > JMP                                                      ->46
   86    37    >   INIT_FCALL                                               'printvalue'
         38        SEND_VAR                                                 !10
         39        DO_FCALL                                      0  $36     
         40        CONCAT                                           ~37     'coerced+to+', $36
         41        ASSIGN                                                   !11, ~37
   87    42      > JMPZ                                                     !8, ->44
   88    43    >   ASSIGN_OP                                     8          !11, '+%28D%29'
   90    44    > > JMPZ                                                     !9, ->46
   91    45    >   ASSIGN_OP                                     8          !11, '+%28N%29'
         46    > > JMP                                                      ->49
   94    47  E > > CATCH                                       last         'Throwable'
   95    48    >   ASSIGN                                                   !11, 'error'
   97    49    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~42     !2, !6
         50        BOOL_NOT                                         ~43     ~42
         51      > JMPZ                                                     ~43, ->54
   98    52    >   ASSIGN_DIM                                               !2, !6
         53        OP_DATA                                                  <array>
  100    54    >   CAST                                          6  ~47     !11
         55        FETCH_DIM_W                                      $45     !2, !6
         56        ASSIGN_DIM                                               $45, !3
         57        OP_DATA                                                  ~47
   66    58      > JMP                                                      ->6
         59    >   FE_FREE                                                  $18
   65    60      > JMP                                                      ->4
         61    >   FE_FREE                                                  $17
  104    62        ECHO                                                     '%0A%0AResults+table%3A%0A%0A'
  106    63        INIT_FCALL                                               'str_pad'
         64        SEND_VAL                                                 'data+type%3A+data'
         65        SEND_VAL                                                 50
         66        SEND_VAL                                                 '+'
         67        SEND_VAL                                                 0
         68        DO_ICALL                                         $48     
         69        CONCAT                                           ~49     '+%7C+', $48
         70        CONCAT                                           ~50     ~49, '+%7C+'
         71        ECHO                                                     ~50
  107    72      > FE_RESET_R                                       $51     !0, ->81
         73    > > FE_FETCH_R                                               $51, !3, ->81
  108    74    >   INIT_FCALL                                               'str_pad'
         75        SEND_VAR                                                 !3
         76        SEND_VAL                                                 20
         77        DO_ICALL                                         $52     
         78        CONCAT                                           ~53     $52, '+%7C+'
         79        ECHO                                                     ~53
  107    80      > JMP                                                      ->73
         81    >   FE_FREE                                                  $51
  110    82        ECHO                                                     '%0A'
  112    83        INIT_FCALL                                               'str_pad'
         84        SEND_VAL                                                 ''
         85        SEND_VAL                                                 50
         86        SEND_VAL                                                 '-'
         87        DO_ICALL                                         $54     
         88        CONCAT                                           ~55     '+%7C+', $54
         89        CONCAT                                           ~56     ~55, '+%7C+'
         90        ECHO                                                     ~56
  113    91      > FE_RESET_R                                       $57     !0, ->101
         92    > > FE_FETCH_R                                               $57, !3, ->101
  114    93    >   INIT_FCALL                                               'str_pad'
         94        SEND_VAL                                                 ''
         95        SEND_VAL                                                 20
         96        SEND_VAL                                                 '-'
         97        DO_ICALL                                         $58     
         98        CONCAT                                           ~59     $58, '+%7C+'
         99        ECHO                                                     ~59
  113   100      > JMP                                                      ->92
        101    >   FE_FREE                                                  $57
  116   102        ECHO                                                     '%0A'
  118   103      > FE_RESET_R                                       $60     !2, ->128
        104    > > FE_FETCH_R                                       ~61     $60, !13, ->128
        105    >   ASSIGN                                                   !5, ~61
  119   106        INIT_FCALL                                               'str_pad'
        107        SEND_VAR                                                 !5
        108        SEND_VAL                                                 50
        109        SEND_VAL                                                 '+'
        110        SEND_VAL                                                 0
        111        DO_ICALL                                         $63     
        112        CONCAT                                           ~64     '+%7C+', $63
        113        CONCAT                                           ~65     ~64, '+%7C+'
        114        ECHO                                                     ~65
  120   115      > FE_RESET_R                                       $66     !13, ->125
        116    > > FE_FETCH_R                                       ~67     $66, !10, ->125
        117    >   ASSIGN                                                   !3, ~67
  121   118        INIT_FCALL                                               'str_pad'
        119        SEND_VAR                                                 !10
        120        SEND_VAL                                                 20
        121        DO_ICALL                                         $69     
        122        CONCAT                                           ~70     $69, '+%7C+'
        123        ECHO                                                     ~70
  120   124      > JMP                                                      ->116
        125    >   FE_FREE                                                  $66
  123   126        ECHO                                                     '%0A'
  118   127      > JMP                                                      ->104
        128    >   FE_FREE                                                  $60
  124   129      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $errno, !1 = $errstr, !2 = $deprecatedFlag, !3 = $noticeFlag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   74     4        IS_IDENTICAL                                             !0, 8
          5      > JMPZ                                                     ~4, ->8
   75     6    >   ASSIGN                                                   !3, <true>
   74     7      > JMP                                                      ->9
   77     8    >   ASSIGN                                                   !2, <true>
   79     9    >   CONCAT                                           ~7      !1, '%0A'
         10        ECHO                                                     ~7
   80    11      > RETURN                                                   null

End of Dynamic Function 0

Function accept_int:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  accept_int
number of ops:  3
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1      > RETURN                                                   !0
    5     2*     > RETURN                                                   null

End of function accept_int

Function accept_float:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  accept_float
number of ops:  3
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1      > RETURN                                                   !0
    8     2*     > RETURN                                                   null

End of function accept_float

Function accept_string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  accept_string
number of ops:  3
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1      > RETURN                                                   !0
   11     2*     > RETURN                                                   null

End of function accept_string

Function accept_bool:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  accept_bool
number of ops:  3
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1      > RETURN                                                   !0
   14     2*     > RETURN                                                   null

End of function accept_bool

Function printvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmHsT
function name:  printValue
number of ops:  23
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~1, ->7
   52     3    >   ROPE_INIT                                     3  ~3      '%22'
          4        ROPE_ADD                                      1  ~3      ~3, !0
          5        ROPE_END                                      2  ~2      ~3, '%22'
          6      > RETURN                                                   ~2
   54     7    >   TYPE_CHECK                                   12          !0
          8      > JMPZ                                                     ~5, ->14
   55     9    > > JMPZ                                                     !0, ->12
         10    >   QM_ASSIGN                                        ~6      'true'
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~6      'false'
         13    > > RETURN                                                   ~6
   57    14    >   TYPE_CHECK                                   32          !0
         15      > JMPZ                                                     ~7, ->21
   58    16    >   INIT_FCALL                                               'number_format'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 1
         19        DO_ICALL                                         $8      
         20      > RETURN                                                   $8
   61    21    > > RETURN                                                   !0
   62    22*     > RETURN                                                   null

End of function printvalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.36 ms | 1023 KiB | 18 Q