3v4l.org

run code in 300+ PHP versions simultaneously
<?php function castToNumber($genericStringNumber) { return $genericStringNumber+0; } //$yourNumberCasted = castToNumber($yourStringNumber); function castNumber($n) { if(!is_numeric($n)) return 0; return (is_float($n)) ? (float) $n : (int) $n; } //$casted = castNumber($num_to_cast); function get_numeric($val) { if (is_numeric($val)) { return $val + 0; } return 0; } var_dump(is_numeric('12.z'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B04XW
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAL                                                 '12.z'
          3        DO_ICALL                                         $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

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

End of function casttonumber

Function castnumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B04XW
function name:  castNumber
number of ops:  16
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->7
          6    > > RETURN                                                   0
   18     7    >   TYPE_CHECK                                   32          !0
          8      > JMPZ                                                     ~3, ->12
          9    >   CAST                                          5  ~4      !0
         10        QM_ASSIGN                                        ~5      ~4
         11      > JMP                                                      ->14
         12    >   CAST                                          4  ~6      !0
         13        QM_ASSIGN                                        ~5      ~6
         14    > > RETURN                                                   ~5
   19    15*     > RETURN                                                   null

End of function castnumber

Function get_numeric:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B04XW
function name:  get_numeric
number of ops:  9
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ                                                     $1, ->7
   26     5    >   ADD                                              ~2      !0, 0
          6      > RETURN                                                   ~2
   28     7    > > RETURN                                                   0
   29     8*     > RETURN                                                   null

End of function get_numeric

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.01 ms | 1392 KiB | 17 Q