3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toBool($var) { if (!is_string($var)) return (bool) $var; switch (strtolower($var)) { case '1': case 'true': case 'on': case 'yes': case 'y': return true; default: return false; } } $strs = ['1', '0', 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n']; foreach ($strs as $str) { echo "toBool($str) : " . (toBool($str) ? 'true' : 'false') . "\n"; echo "filter_var($str) : " . (filter_var($str, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? 'true' : 'false') . "\n"; echo "parse_ini_string($str): " . (parse_ini_string("val = $str")['val'] ? 'true' : 'false') . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 48
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 48
Branch analysis from position: 3
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
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
Branch analysis from position: 43
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
Branch analysis from position: 27
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/sgb7D
function name:  (null)
number of ops:  50
compiled vars:  !0 = $strs, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   18     1      > FE_RESET_R                                       $3      !0, ->48
          2    > > FE_FETCH_R                                               $3, !1, ->48
   19     3    >   ROPE_INIT                                     3  ~5      'toBool%28'
          4        ROPE_ADD                                      1  ~5      ~5, !1
          5        ROPE_END                                      2  ~4      ~5, '%29++++++++++%3A+'
          6        INIT_FCALL                                               'tobool'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $7      
          9      > JMPZ                                                     $7, ->12
         10    >   QM_ASSIGN                                        ~8      'true'
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~8      'false'
         13    >   CONCAT                                           ~9      ~4, ~8
         14        CONCAT                                           ~10     ~9, '%0A'
         15        ECHO                                                     ~10
   20    16        ROPE_INIT                                     3  ~12     'filter_var%28'
         17        ROPE_ADD                                      1  ~12     ~12, !1
         18        ROPE_END                                      2  ~11     ~12, '%29++++++%3A+'
         19        INIT_FCALL                                               'filter_var'
         20        SEND_VAR                                                 !1
         21        SEND_VAL                                                 258
         22        SEND_VAL                                                 134217728
         23        DO_ICALL                                         $14     
         24      > JMPZ                                                     $14, ->27
         25    >   QM_ASSIGN                                        ~15     'true'
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~15     'false'
         28    >   CONCAT                                           ~16     ~11, ~15
         29        CONCAT                                           ~17     ~16, '%0A'
         30        ECHO                                                     ~17
   21    31        ROPE_INIT                                     3  ~19     'parse_ini_string%28'
         32        ROPE_ADD                                      1  ~19     ~19, !1
         33        ROPE_END                                      2  ~18     ~19, '%29%3A+'
         34        INIT_FCALL                                               'parse_ini_string'
         35        NOP                                                      
         36        FAST_CONCAT                                      ~21     'val+%3D+', !1
         37        SEND_VAL                                                 ~21
         38        DO_ICALL                                         $22     
         39        FETCH_DIM_R                                      ~23     $22, 'val'
         40      > JMPZ                                                     ~23, ->43
         41    >   QM_ASSIGN                                        ~24     'true'
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~24     'false'
         44    >   CONCAT                                           ~25     ~18, ~24
         45        CONCAT                                           ~26     ~25, '%0A'
         46        ECHO                                                     ~26
   18    47      > JMP                                                      ->2
         48    >   FE_FREE                                                  $3
   22    49      > RETURN                                                   1

Function tobool:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 20
Branch analysis from position: 20
Branch analysis from position: 20
filename:       /in/sgb7D
function name:  toBool
number of ops:  26
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        TYPE_CHECK                                   64  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->6
          4    >   BOOL                                             ~3      !0
          5      > RETURN                                                   ~3
    5     6    >   INIT_FCALL                                               'strtolower'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
    6     9        CASE                                                     $4, '1'
         10      > JMPNZ                                                    ~5, ->20
    7    11    >   CASE                                                     $4, 'true'
         12      > JMPNZ                                                    ~5, ->20
    8    13    >   CASE                                                     $4, 'on'
         14      > JMPNZ                                                    ~5, ->20
    9    15    >   CASE                                                     $4, 'yes'
         16      > JMPNZ                                                    ~5, ->20
   10    17    >   CASE                                                     $4, 'y'
         18      > JMPNZ                                                    ~5, ->20
         19    > > JMP                                                      ->22
   11    20    >   FREE                                                     $4
         21      > RETURN                                                   <true>
   13    22    >   FREE                                                     $4
         23      > RETURN                                                   <false>
         24*       FREE                                                     $4
   15    25*     > RETURN                                                   null

End of function tobool

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.88 ms | 1013 KiB | 17 Q