3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ) { return abs( (int) $maybeint ); } function new_absint( $maybeint ): int { 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(); 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/nvmke
function name:  (null)
number of ops:  19
compiled vars:  !0 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   NEW                                                  $1      'StdClass'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   41     3        INIT_FCALL                                                   'var_dump'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                                     
   42     6        INIT_FCALL                                                   'var_dump'
          7        INIT_FCALL                                                   'absint'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $5      
         10        SEND_VAR                                                     $5
         11        DO_ICALL                                                     
   43    12        INIT_FCALL                                                   'var_dump'
         13        INIT_FCALL                                                   'new_absint'
         14        SEND_VAR                                                     !0
         15        DO_FCALL                                          0  $7      
         16        SEND_VAR                                                     $7
         17        DO_ICALL                                                     
         18      > RETURN                                                       1

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

End of function new_absint

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.98 ms | 1433 KiB | 18 Q