3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * A polyfill library with PHP 7's improved way of doing integer division * * @author Michael Cullum <m@michaelcullum.com> * @license http://www.opensource.org/licenses/mit-license.html MIT License * @copyright 2015 Michael Cullum */ namespace { if (!function_exists('intdiv')) { function intdiv($dividend, $divisor) { $dividend = (int) $dividend; $divisor = (int) $divisor; if ($divisor === 0) { throw new DivisionByZeroError('Division by zero'); } if ($divisor === -1 && $dividend == ~PHP_INT_MAX) { throw new ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer'); } $dividend = ($dividend - $dividend % $divisor); return ((int) ($dividend / $divisor)); } } if (!class_exists('ArithmeticError') || !class_exists('DivisionByZeroError')) { if (!class_exists('Throwable')) { class Throwable extends \Exception { public function __toString() { return $this->getMessage(); } } } if (!class_exists('Error')) { class Error extends Throwable { public function __toString() { return $this->getMessage(); } } } if (!class_exists('ArithmeticError')) { class ArithmeticError extends Error { public function __toString() { return $this->getMessage(); } } } if (!class_exists('DivisionByZeroError')) { class DivisionByZeroError extends Error { public function __toString() { return $this->getMessage(); } } } } foreach (array('Error', 'ArithmeticError', 'DivisionByZeroError') as $class) { print_r(class_implements($class)); if (!count(array_intersect(array('Exception', 'Throwable'), class_implements($class)))) { throw new \RuntimeException('A class named \''.$class.'\' is already defined that cannot be thrown.'); } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 41
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 66
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 66
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 65
Branch analysis from position: 59
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 41
Branch analysis from position: 35
Branch analysis from position: 29
Branch analysis from position: 23
Branch analysis from position: 41
Branch analysis from position: 16
Branch analysis from position: 6
filename:       /in/rZLLA
function name:  (null)
number of ops:  68
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'intdiv'
          2        DO_ICALL                                         $1      
          3        BOOL_NOT                                         ~2      $1
          4      > JMPZ                                                     ~2, ->6
   11     5    >   DECLARE_FUNCTION                                         'intdiv'
   25     6    >   INIT_FCALL                                               'class_exists'
          7        SEND_VAL                                                 'ArithmeticError'
          8        DO_ICALL                                         $3      
          9        BOOL_NOT                                         ~4      $3
         10      > JMPNZ_EX                                         ~4      ~4, ->16
         11    >   INIT_FCALL                                               'class_exists'
         12        SEND_VAL                                                 'DivisionByZeroError'
         13        DO_ICALL                                         $5      
         14        BOOL_NOT                                         ~6      $5
         15        BOOL                                             ~4      ~6
         16    > > JMPZ                                                     ~4, ->41
   26    17    >   INIT_FCALL                                               'class_exists'
         18        SEND_VAL                                                 'Throwable'
         19        DO_ICALL                                         $7      
         20        BOOL_NOT                                         ~8      $7
         21      > JMPZ                                                     ~8, ->23
   27    22    >   DECLARE_CLASS                                            'throwable', 'exception'
   35    23    >   INIT_FCALL                                               'class_exists'
         24        SEND_VAL                                                 'Error'
         25        DO_ICALL                                         $9      
         26        BOOL_NOT                                         ~10     $9
         27      > JMPZ                                                     ~10, ->29
   36    28    >   DECLARE_CLASS                                            'error', 'throwable'
   44    29    >   INIT_FCALL                                               'class_exists'
         30        SEND_VAL                                                 'ArithmeticError'
         31        DO_ICALL                                         $11     
         32        BOOL_NOT                                         ~12     $11
         33      > JMPZ                                                     ~12, ->35
   45    34    >   DECLARE_CLASS                                            'arithmeticerror', 'error'
   53    35    >   INIT_FCALL                                               'class_exists'
         36        SEND_VAL                                                 'DivisionByZeroError'
         37        DO_ICALL                                         $13     
         38        BOOL_NOT                                         ~14     $13
         39      > JMPZ                                                     ~14, ->41
   54    40    >   DECLARE_CLASS                                            'divisionbyzeroerror', 'error'
   63    41    > > FE_RESET_R                                       $15     <array>, ->66
         42    > > FE_FETCH_R                                               $15, !0, ->66
   64    43    >   INIT_FCALL                                               'print_r'
         44        INIT_FCALL                                               'class_implements'
         45        SEND_VAR                                                 !0
         46        DO_ICALL                                         $16     
         47        SEND_VAR                                                 $16
         48        DO_ICALL                                                 
   65    49        INIT_FCALL                                               'array_intersect'
         50        SEND_VAL                                                 <array>
         51        INIT_FCALL                                               'class_implements'
         52        SEND_VAR                                                 !0
         53        DO_ICALL                                         $18     
         54        SEND_VAR                                                 $18
         55        DO_ICALL                                         $19     
         56        COUNT                                            ~20     $19
         57        BOOL_NOT                                         ~21     ~20
         58      > JMPZ                                                     ~21, ->65
   66    59    >   NEW                                              $22     'RuntimeException'
         60        CONCAT                                           ~23     'A+class+named+%27', !0
         61        CONCAT                                           ~24     ~23, '%27+is+already+defined+that+cannot+be+thrown.'
         62        SEND_VAL_EX                                              ~24
         63        DO_FCALL                                      0          
         64      > THROW                                         0          $22
   63    65    > > JMP                                                      ->42
         66    >   FE_FREE                                                  $15
   69    67      > RETURN                                                   1

Function %00intdiv%2Fin%2FrZLLA%3A11%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/rZLLA
function name:  intdiv
number of ops:  28
compiled vars:  !0 = $dividend, !1 = $divisor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        CAST                                          4  ~2      !0
          3        ASSIGN                                                   !0, ~2
   14     4        CAST                                          4  ~4      !1
          5        ASSIGN                                                   !1, ~4
   15     6        IS_IDENTICAL                                             !1, 0
          7      > JMPZ                                                     ~6, ->12
   16     8    >   NEW                                              $7      'DivisionByZeroError'
          9        SEND_VAL_EX                                              'Division+by+zero'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $7
   18    12    >   IS_IDENTICAL                                     ~9      !1, -1
         13      > JMPZ_EX                                          ~9      ~9, ->16
         14    >   IS_EQUAL                                         ~10     !0, -9223372036854775808
         15        BOOL                                             ~9      ~10
         16    > > JMPZ                                                     ~9, ->21
   19    17    >   NEW                                              $11     'ArithmeticError'
         18        SEND_VAL_EX                                              'Division+of+PHP_INT_MIN+by+-1+is+not+an+integer'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $11
   21    21    >   MOD                                              ~13     !0, !1
         22        SUB                                              ~14     !0, ~13
         23        ASSIGN                                                   !0, ~14
   22    24        DIV                                              ~16     !0, !1
         25        CAST                                          4  ~17     ~16
         26      > RETURN                                                   ~17
   23    27*     > RETURN                                                   null

End of function %00intdiv%2Fin%2FrZLLA%3A11%240

Class Throwable:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rZLLA
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_METHOD_CALL                                         'getMessage'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   32     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class Throwable.

Class Error:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rZLLA
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_METHOD_CALL                                         'getMessage'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   41     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class Error.

Class ArithmeticError:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rZLLA
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_METHOD_CALL                                         'getMessage'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   50     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class ArithmeticError.

Class DivisionByZeroError:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rZLLA
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_METHOD_CALL                                         'getMessage'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   59     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class DivisionByZeroError.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
257.96 ms | 954 KiB | 25 Q