3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * A code sample which converts odd integers to word strings and returns the sum of the common factors of even numbers. * * The input is assumed to be a random list of integers. For the sum of the common factors of even numbers * only positive values are taken into consideration */ error_reporting(E_ALL); function exception_handler($exception) { echo get_class($exception). ' : ' . $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); //start $iB = new IntelligentBee(array(6,12,48, 7, 101, 67)); //$iB->processOddNumbers(); //$sum = $iB->processEvenNumbers(); //echo PHP_EOL.'Sum of common factors: ' . $sum . PHP_EOL; $a = $iB->getCmmdcSum(); echo PHP_EOL.' Sum is ' . $a[1]. PHP_EOL; //end class IntelligentBee{ const OneHundred = 100; const OneThousand = 1000; const OneMillion = 1000000; const OneBillion = 1000000000; protected $minCommonFactors = []; protected $oddNumbers = []; protected $evenNumbers = []; protected $startInt; protected $endInt; public function __construct(array $arrayOfIntegers){ $startInt = min($arrayOfIntegers); $endInt = max($arrayOfIntegers); if(abs($startInt) > self::OneBillion || abs($startInt) > self::OneBillion){ throw new OutOfRangeException(sprintf("We can only process numbers between %s and %s! %s provided!", self::OneBillion, self::OneBillion, $startInt)); } if(abs($endInt) > self::OneBillion || abs($endInt) > self::OneBillion){ throw new OutOfRangeException(sprintf("We can only process numbers between %s and %s! %s provided!", self::OneBillion, self::OneBillion, $startInt)); } $this->startInt = $startInt; $this->endInt = $endInt; $arrayOfIntegers = range(2, self::OneMillion,2); } public function getCmmdcSum() { $values = $this->evenNumbers; $num_values = count($values); $x = current($values); $y = next($values); for ($i = 1; $i < $num_values; $i ++) { $a = max($x, $y); $b = min($x, $y); $c= 1; do { $c = $a % $b; $gcf = $b; $a = $b; $b = $c; } while ($c != 0); $x = $gcf; $y = next($values); } $sum = 0; for($i = 1; $i <= $gcf; $i ++){ if(0 === $gcf % $i){ $sum += $i; } } return array($gcf, $sum); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qulh9
function name:  (null)
number of ops:  18
compiled vars:  !0 = $iB, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   16     3        INIT_FCALL                                               'set_exception_handler'
          4        SEND_VAL                                                 'exception_handler'
          5        DO_ICALL                                                 
   20     6        NEW                                              $4      'IntelligentBee'
          7        SEND_VAL_EX                                              <array>
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $4
   24    10        INIT_METHOD_CALL                                         !0, 'getCmmdcSum'
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !1, $7
   25    13        FETCH_DIM_R                                      ~9      !1, 1
         14        CONCAT                                           ~10     '%0A+Sum+is+', ~9
         15        CONCAT                                           ~11     ~10, '%0A'
         16        ECHO                                                     ~11
   96    17      > RETURN                                                   1

Function exception_handler:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qulh9
function name:  exception_handler
number of ops:  9
compiled vars:  !0 = $exception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        GET_CLASS                                        ~1      !0
          2        CONCAT                                           ~2      ~1, '+%3A+'
          3        INIT_METHOD_CALL                                         !0, 'getMessage'
          4        DO_FCALL                                      0  $3      
          5        CONCAT                                           ~4      ~2, $3
          6        ECHO                                                     ~4
          7        ECHO                                                     '%0A'
   15     8      > RETURN                                                   null

End of function exception_handler

Class IntelligentBee:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 30
Branch analysis from position: 20
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 47) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 51
Branch analysis from position: 41
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 19
filename:       /in/Qulh9
function name:  __construct
number of ops:  62
compiled vars:  !0 = $arrayOfIntegers, !1 = $startInt, !2 = $endInt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        INIT_FCALL                                               'min'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
   45     5        INIT_FCALL                                               'max'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !2, $5
   47     9        INIT_FCALL                                               'abs'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $7      
         12        IS_SMALLER                                       ~8      1000000000, $7
         13      > JMPNZ_EX                                         ~8      ~8, ->19
         14    >   INIT_FCALL                                               'abs'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $9      
         17        IS_SMALLER                                       ~10     1000000000, $9
         18        BOOL                                             ~8      ~10
         19    > > JMPZ                                                     ~8, ->30
   48    20    >   NEW                                              $11     'OutOfRangeException'
         21        INIT_FCALL                                               'sprintf'
         22        SEND_VAL                                                 'We+can+only+process+numbers+between+%25s+and+%25s%21+%25s+provided%21'
         23        SEND_VAL                                                 1000000000
         24        SEND_VAL                                                 1000000000
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $12     
         27        SEND_VAR_NO_REF_EX                                       $12
         28        DO_FCALL                                      0          
         29      > THROW                                         0          $11
   51    30    >   INIT_FCALL                                               'abs'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $14     
         33        IS_SMALLER                                       ~15     1000000000, $14
         34      > JMPNZ_EX                                         ~15     ~15, ->40
         35    >   INIT_FCALL                                               'abs'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $16     
         38        IS_SMALLER                                       ~17     1000000000, $16
         39        BOOL                                             ~15     ~17
         40    > > JMPZ                                                     ~15, ->51
   52    41    >   NEW                                              $18     'OutOfRangeException'
         42        INIT_FCALL                                               'sprintf'
         43        SEND_VAL                                                 'We+can+only+process+numbers+between+%25s+and+%25s%21+%25s+provided%21'
         44        SEND_VAL                                                 1000000000
         45        SEND_VAL                                                 1000000000
         46        SEND_VAR                                                 !1
         47        DO_ICALL                                         $19     
         48        SEND_VAR_NO_REF_EX                                       $19
         49        DO_FCALL                                      0          
         50      > THROW                                         0          $18
   55    51    >   ASSIGN_OBJ                                               'startInt'
         52        OP_DATA                                                  !1
   56    53        ASSIGN_OBJ                                               'endInt'
         54        OP_DATA                                                  !2
   57    55        INIT_FCALL                                               'range'
         56        SEND_VAL                                                 2
         57        SEND_VAL                                                 1000000
         58        SEND_VAL                                                 2
         59        DO_ICALL                                         $23     
         60        ASSIGN                                                   !0, $23
   59    61      > RETURN                                                   null

End of function __construct

Function getcmmdcsum:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 14
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 43
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 43
Branch analysis from position: 50
Branch analysis from position: 43
Branch analysis from position: 47
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 25
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 14
Branch analysis from position: 40
Branch analysis from position: 14
Branch analysis from position: 25
filename:       /in/Qulh9
function name:  getCmmdcSum
number of ops:  54
compiled vars:  !0 = $values, !1 = $num_values, !2 = $x, !3 = $y, !4 = $i, !5 = $a, !6 = $b, !7 = $c, !8 = $gcf, !9 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   FETCH_OBJ_R                                      ~10     'evenNumbers'
          1        ASSIGN                                                   !0, ~10
   65     2        COUNT                                            ~12     !0
          3        ASSIGN                                                   !1, ~12
   67     4        INIT_FCALL                                               'current'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $14     
          7        ASSIGN                                                   !2, $14
   68     8        INIT_FCALL                                               'next'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                         $16     
         11        ASSIGN                                                   !3, $16
   70    12        ASSIGN                                                   !4, 1
         13      > JMP                                                      ->38
   71    14    >   INIT_FCALL                                               'max'
         15        SEND_VAR                                                 !2
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $19     
         18        ASSIGN                                                   !5, $19
   72    19        INIT_FCALL                                               'min'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $21     
         23        ASSIGN                                                   !6, $21
   73    24        ASSIGN                                                   !7, 1
   75    25    >   MOD                                              ~24     !5, !6
         26        ASSIGN                                                   !7, ~24
   76    27        ASSIGN                                                   !8, !6
   77    28        ASSIGN                                                   !5, !6
   78    29        ASSIGN                                                   !6, !7
   79    30        IS_NOT_EQUAL                                             !7, 0
         31      > JMPNZ                                                    ~29, ->25
   80    32    >   ASSIGN                                                   !2, !8
   81    33        INIT_FCALL                                               'next'
         34        SEND_REF                                                 !0
         35        DO_ICALL                                         $31     
         36        ASSIGN                                                   !3, $31
   70    37        PRE_INC                                                  !4
         38    >   IS_SMALLER                                               !4, !1
         39      > JMPNZ                                                    ~34, ->14
   84    40    >   ASSIGN                                                   !9, 0
   85    41        ASSIGN                                                   !4, 1
         42      > JMP                                                      ->48
   86    43    >   MOD                                              ~37     !8, !4
         44        IS_IDENTICAL                                             ~37, 0
         45      > JMPZ                                                     ~38, ->47
   87    46    >   ASSIGN_OP                                     1          !9, !4
   85    47    >   PRE_INC                                                  !4
         48    >   IS_SMALLER_OR_EQUAL                                      !4, !8
         49      > JMPNZ                                                    ~41, ->43
   91    50    >   INIT_ARRAY                                       ~42     !8
         51        ADD_ARRAY_ELEMENT                                ~42     !9
         52      > RETURN                                                   ~42
   92    53*     > RETURN                                                   null

End of function getcmmdcsum

End of class IntelligentBee.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.86 ms | 1408 KiB | 31 Q