3v4l.org

run code in 500+ PHP versions simultaneously
<?php function absint( $maybeint ): int { if ( ! is_numeric( $maybeint ) ) { return 0; } if ( is_float( $maybeint ) ) { $value = abs( $maybeint ); if ( $value >= PHP_INT_MAX ) { return PHP_INT_MAX; } else { return (int) $value; } } // Convert numeric-string to int. $value = (int) $maybeint; // Special case for the one integer which cannot survive abs(). if ( PHP_INT_MIN === $value ) { return PHP_INT_MAX; } return abs( $value ); } $maybeints = array( 'positive max int times 2' => PHP_INT_MAX * 2, 'zero' => 0, 'string' => 'foo', 'negative 1 int' => -1, 'positive 1 int' => 1, 'negative min int' => PHP_INT_MIN, 'negative min int minus 1' => PHP_INT_MIN - 1, 'negative min int times 2' => PHP_INT_MIN * 2, 'positive max int' => PHP_INT_MAX, 'positive max int plus 1' => PHP_INT_MAX + 1, 'positive max int as string' => (string) PHP_INT_MAX, 'positive max int times 1000 as string' => (string) PHP_INT_MAX . '000', ); foreach ( $maybeints as $case => $maybeint ) { echo "# $case\n\n"; echo 'Input: '; var_dump( $maybeint ); echo 'Output: '; var_dump( absint( $maybeint ) ); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 21
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/vuYa8
function name:  (null)
number of ops:  23
compiled vars:  !0 = $maybeints, !1 = $maybeint, !2 = $case
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                       !0, <array>
   41     1      > FE_RESET_R                                           $4      !0, ->21
          2    > > FE_FETCH_R                                           ~5      $4, !1, ->21
          3    >   ASSIGN                                                       !2, ~5
   42     4        ROPE_INIT                                         3  ~8      '%23+'
          5        ROPE_ADD                                          1  ~8      ~8, !2
          6        ROPE_END                                          2  ~7      ~8, '%0A%0A'
          7        ECHO                                                         ~7
   43     8        ECHO                                                         'Input%3A++'
   44     9        INIT_FCALL                                                   'var_dump'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                                     
   45    12        ECHO                                                         'Output%3A+'
   46    13        INIT_FCALL                                                   'var_dump'
         14        INIT_FCALL                                                   'absint'
         15        SEND_VAR                                                     !1
         16        DO_FCALL                                          0  $11     
         17        SEND_VAR                                                     $11
         18        DO_ICALL                                                     
   47    19        ECHO                                                         '%0A'
   41    20      > JMP                                                          ->2
         21    >   FE_FREE                                                      $4
   48    22      > RETURN                                                       1

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

End of function absint

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.83 ms | 3747 KiB | 16 Q