3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ) { return abs( (int) $maybeint ); } function new_absint( $maybeint ): int { if ( is_object( $maybeint ) ) { return 1; } if ( is_float( $maybeint ) ) { if ( ! is_finite( $maybeint ) ) { // Casting `NAN` or `INF` to int has produced `0` since PHP 7.0. return 0; } if ( $maybeint <= (float) PHP_INT_MIN || $maybeint >= (float) PHP_INT_MAX ) { // Casting a float beyond the integer range is unreliable and warns as of PHP 8.5. return PHP_INT_MAX; } } $maybeint = (int) $maybeint; if ( PHP_INT_MIN === $maybeint ) { // `abs( PHP_INT_MIN )` overflows to a float, as `PHP_INT_MAX` is one less than `-PHP_INT_MIN`. return PHP_INT_MAX; } return abs( $maybeint ); } #$data = '999 stuff'; // same #$data = '999999999999999999222222222288888888888888222222222227777777774444'; // same, warning is gone in newer version of PHP 8.5 ( 8.5.2+ ) #$data = -PHP_INT_MIN; // original: float, new: int -- and the numbers differ by 1 #$data = 'now is the time'; // same ( zero ) #$data = -PHP_INT_MAX; // same #$data = PHP_INT_MAX + 1; // original: float ( 9.223372036854776E+18 ), new: int ( 9223372036854775807 ) -- very different numbers #$data = PHP_INT_MIN - 1; // original: float( 9.223372036854776E+18 ), new: int( 9223372036854775807 ) -- very different numbers $data = new StdClass(); $data->name = 'data'; $data->place = 'where'; $data->stuff = [ 'green', 'blue', 'red' ]; var_dump( $data ); var_dump( absint( $data ) ); var_dump( new_absint( $data ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EMGrO
function name:  (null)
number of ops:  25
compiled vars:  !0 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   NEW                                                  $1      'StdClass'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   43     3        ASSIGN_OBJ                                                   !0, 'name'
          4        OP_DATA                                                      'data'
   44     5        ASSIGN_OBJ                                                   !0, 'place'
          6        OP_DATA                                                      'where'
   45     7        ASSIGN_OBJ                                                   !0, 'stuff'
          8        OP_DATA                                                      <array>
   48     9        INIT_FCALL                                                   'var_dump'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                                     
   49    12        INIT_FCALL                                                   'var_dump'
         13        INIT_FCALL                                                   'absint'
         14        SEND_VAR                                                     !0
         15        DO_FCALL                                          0  $8      
         16        SEND_VAR                                                     $8
         17        DO_ICALL                                                     
   50    18        INIT_FCALL                                                   'var_dump'
         19        INIT_FCALL                                                   'new_absint'
         20        SEND_VAR                                                     !0
         21        DO_FCALL                                          0  $10     
         22        SEND_VAR                                                     $10
         23        DO_ICALL                                                     
         24      > RETURN                                                       1

Function absint:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EMGrO
function name:  absint
number of ops:  7
compiled vars:  !0 = $maybeint
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        INIT_FCALL                                                   'abs'
          2        CAST                                              4  ~1      !0
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                             $2      
          5      > RETURN                                                       $2
    5     6*     > RETURN                                                       null

End of function absint

Function new_absint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
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 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 20
filename:       /in/EMGrO
function name:  new_absint
number of ops:  32
compiled vars:  !0 = $maybeint
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        TYPE_CHECK                                      256          !0
          2      > JMPZ                                                         ~1, ->4
    9     3    > > RETURN                                                       1
   12     4    >   TYPE_CHECK                                       32          !0
          5      > JMPZ                                                         ~2, ->20
   13     6    >   INIT_FCALL                                                   'is_finite'
          7        SEND_VAR                                                     !0
          8        DO_ICALL                                             $3      
          9        BOOL_NOT                                             ~4      $3
         10      > JMPZ                                                         ~4, ->12
   15    11    > > RETURN                                                       0
   18    12    >   CAST                                              5  ~5      -9223372036854775808
         13        IS_SMALLER_OR_EQUAL                                  ~6      !0, ~5
         14      > JMPNZ_EX                                             ~6      ~6, ->18
         15    >   CAST                                              5  ~7      9223372036854775807
         16        IS_SMALLER_OR_EQUAL                                  ~8      ~7, !0
         17        BOOL                                                 ~6      ~8
         18    > > JMPZ                                                         ~6, ->20
   20    19    > > RETURN                                                       9223372036854775807
   24    20    >   CAST                                              4  ~9      !0
         21        ASSIGN                                                       !0, ~9
   26    22        IS_IDENTICAL                                                 !0, -9223372036854775808
         23      > JMPZ                                                         ~11, ->25
   28    24    > > RETURN                                                       9223372036854775807
   31    25    >   INIT_FCALL                                                   'abs'
         26        SEND_VAR                                                     !0
         27        DO_ICALL                                             $12     
         28        VERIFY_RETURN_TYPE                                           $12
         29      > RETURN                                                       $12
   32    30*       VERIFY_RETURN_TYPE                                           
         31*     > RETURN                                                       null

End of function new_absint

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.66 ms | 1442 KiB | 18 Q