3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(to_int('1.')); var_dump(to_int('1...')); /** * Returns the value as an int, or false if it cannot be safely cast * @param mixed $val * @return int */ function to_int($val) { switch (gettype($val)) { case "integer": return $val; case "double": if ($val === (float) (int) $val) { return (int) $val; } else { return false; } case "string": $val = trim($val, " \t\n\r\v\f"); // trim whitespace $float = filter_var($val, FILTER_VALIDATE_FLOAT); return ($float !== false && (int) $val == $float) ? (int) $val : false; default: return false; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YOaue
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL_BY_NAME                                       'to_int'
          2        SEND_VAL_EX                                              '1.'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
    4     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL_BY_NAME                                       'to_int'
          8        SEND_VAL_EX                                              '1...'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   29    12      > RETURN                                                   1

Function to_int:
Finding entry points
Branch analysis from position: 0
5 jumps found. (Code = 188) Position 1 = 10, Position 2 = 12, Position 3 = 22, Position 4 = 44, Position 5 = 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
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: 22
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 22
Branch analysis from position: 12
Branch analysis from position: 10
filename:       /in/YOaue
function name:  to_int
number of ops:  48
compiled vars:  !0 = $val, !1 = $float
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        GET_TYPE                                         ~2      !0
          2      > SWITCH_STRING                                            ~2, [ 'integer':->10, 'double':->12, 'string':->22, ], ->44
   14     3    >   CASE                                                     ~2, 'integer'
          4      > JMPNZ                                                    ~3, ->10
   16     5    >   CASE                                                     ~2, 'double'
          6      > JMPNZ                                                    ~3, ->12
   22     7    >   CASE                                                     ~2, 'string'
          8      > JMPNZ                                                    ~3, ->22
          9    > > JMP                                                      ->44
   15    10    >   FREE                                                     ~2
         11      > RETURN                                                   !0
   17    12    >   CAST                                          4  ~4      !0
         13        CAST                                          5  ~5      ~4
         14        IS_IDENTICAL                                             !0, ~5
         15      > JMPZ                                                     ~6, ->20
   18    16    >   CAST                                          4  ~7      !0
         17        FREE                                                     ~2
         18      > RETURN                                                   ~7
         19*       JMP                                                      ->22
   20    20    >   FREE                                                     ~2
         21      > RETURN                                                   <false>
   23    22    >   INIT_FCALL                                               'trim'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 '+%09%0A%0D%0B%0C'
         25        DO_ICALL                                         $8      
         26        ASSIGN                                                   !0, $8
   24    27        INIT_FCALL                                               'filter_var'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 259
         30        DO_ICALL                                         $10     
         31        ASSIGN                                                   !1, $10
   25    32        TYPE_CHECK                                  1018  ~12     !1
         33      > JMPZ_EX                                          ~12     ~12, ->37
         34    >   CAST                                          4  ~13     !0
         35        IS_EQUAL                                         ~14     !1, ~13
         36        BOOL                                             ~12     ~14
         37    > > JMPZ                                                     ~12, ->41
         38    >   CAST                                          4  ~15     !0
         39        QM_ASSIGN                                        ~16     ~15
         40      > JMP                                                      ->42
         41    >   QM_ASSIGN                                        ~16     <false>
         42    >   FREE                                                     ~2
         43      > RETURN                                                   ~16
   27    44    >   FREE                                                     ~2
         45      > RETURN                                                   <false>
         46*       FREE                                                     ~2
   29    47*     > RETURN                                                   null

End of function to_int

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.06 ms | 1400 KiB | 19 Q