3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Shipping { /** * @return integer The minimum number of boxes needed to hold a given number of items */ public static function minimalNumberOfPackages($items, $availableLargePackages, $availableSmallPackages) { $maxSize = 5; if ($items < $maxSize) return $items; if (($items - ($maxSize * $availableLargePackages + $availableSmallPackages)) > 0) return -1; $itemsNotHoldByMax = $items / 5; if ($itemsNotHoldByMax > $items) $itemsNotHoldByMax = $availableLargePackages; return $itemsNotHoldByMax + ($items - $maxSize * $itemsNotHoldByMax); } public static function minimalNumberOfBoxes2( $products, $availableLargeBoxes, $availableSmallBoxes) { if ($products < 5) return $products; if (($products - (5 * $availableLargeBoxes + $availableSmallBoxes)) > 0) return -1; $rl = $products / 5; if ($rl > $availableLargeBoxes) $rl = $availableLargeBoxes; return $rl + ($products - 5 * $rl); } } echo Shipping::minimalNumberOfPackages2(16, 2, 10);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6MW80
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   INIT_STATIC_METHOD_CALL                                  'Shipping', 'minimalNumberOfPackages2'
          1        SEND_VAL_EX                                              16
          2        SEND_VAL_EX                                              2
          3        SEND_VAL_EX                                              10
          4        DO_FCALL                                      0  $0      
          5        ECHO                                                     $0
          6      > RETURN                                                   1

Class Shipping:
Function minimalnumberofpackages:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/6MW80
function name:  minimalNumberOfPackages
number of ops:  23
compiled vars:  !0 = $items, !1 = $availableLargePackages, !2 = $availableSmallPackages, !3 = $maxSize, !4 = $itemsNotHoldByMax
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ASSIGN                                                   !3, 5
   11     4        IS_SMALLER                                               !0, !3
          5      > JMPZ                                                     ~6, ->7
   12     6    > > RETURN                                                   !0
   14     7    >   MUL                                              ~7      !3, !1
          8        ADD                                              ~8      ~7, !2
          9        SUB                                              ~9      !0, ~8
         10        IS_SMALLER                                               0, ~9
         11      > JMPZ                                                     ~10, ->13
   15    12    > > RETURN                                                   -1
   17    13    >   DIV                                              ~11     !0, 5
         14        ASSIGN                                                   !4, ~11
   18    15        IS_SMALLER                                               !0, !4
         16      > JMPZ                                                     ~13, ->18
   19    17    >   ASSIGN                                                   !4, !1
   21    18    >   MUL                                              ~15     !3, !4
         19        SUB                                              ~16     !0, ~15
         20        ADD                                              ~17     !4, ~16
         21      > RETURN                                                   ~17
   22    22*     > RETURN                                                   null

End of function minimalnumberofpackages

Function minimalnumberofboxes2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
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 = 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
filename:       /in/6MW80
function name:  minimalNumberOfBoxes2
number of ops:  22
compiled vars:  !0 = $products, !1 = $availableLargeBoxes, !2 = $availableSmallBoxes, !3 = $rl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   26     3        IS_SMALLER                                               !0, 5
          4      > JMPZ                                                     ~4, ->6
   27     5    > > RETURN                                                   !0
   29     6    >   MUL                                              ~5      !1, 5
          7        ADD                                              ~6      ~5, !2
          8        SUB                                              ~7      !0, ~6
          9        IS_SMALLER                                               0, ~7
         10      > JMPZ                                                     ~8, ->12
   30    11    > > RETURN                                                   -1
   32    12    >   DIV                                              ~9      !0, 5
         13        ASSIGN                                                   !3, ~9
   34    14        IS_SMALLER                                               !1, !3
         15      > JMPZ                                                     ~11, ->17
   35    16    >   ASSIGN                                                   !3, !1
   37    17    >   MUL                                              ~13     !3, 5
         18        SUB                                              ~14     !0, ~13
         19        ADD                                              ~15     !3, ~14
         20      > RETURN                                                   ~15
   38    21*     > RETURN                                                   null

End of function minimalnumberofboxes2

End of class Shipping.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.23 ms | 1399 KiB | 13 Q