3v4l.org

run code in 300+ PHP versions simultaneously
<?php function oldGetMinPrice($num1, $num2) { if(!(is_numeric($num1) && $num1 >0) && !(is_numeric($num2) && $num2 >0) ) { return 'error'; } $num1 = (float)$num1; $num2 = (float)$num2; echo "($num1 & $num2) "; if($num1 <= 0) { return $num2; } if($num2 <= 0) { return $num1; } return min($num1,$num2); } function newGetMinPrice($nums) { $nums = array_filter($nums, function($v){ return (float)$v > 0;}); // convert to float and check if greater than 0 if (empty($nums)) { return 'error'; // if no qualifying prices, return error } return min($nums); // return the lowest qualifying price } $tests = [[0, .1], [1, 'foo'], [.24, -.25], [3, 3], ['foo', 'bar'], [-0, 0.1], [90, -90], [0, 0], [1, 1]]; foreach ($tests as $test) { echo "old: {$test[0]} -vs- {$test[1]} = ",oldGetMinPrice($test[0], $test[1]), "\n"; echo "new: {$test[0]} -vs- {$test[1]} = ",newGetMinPrice($test), "\n\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 33
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/653oT
function name:  (null)
number of ops:  35
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_R                                       $3      !0, ->33
          2    > > FE_FETCH_R                                               $3, !1, ->33
   27     3    >   ROPE_INIT                                     5  ~7      'old%3A+'
          4        FETCH_DIM_R                                      ~4      !1, 0
          5        ROPE_ADD                                      1  ~7      ~7, ~4
          6        ROPE_ADD                                      2  ~7      ~7, '+-vs-+'
          7        FETCH_DIM_R                                      ~5      !1, 1
          8        ROPE_ADD                                      3  ~7      ~7, ~5
          9        ROPE_END                                      4  ~6      ~7, '+%3D+'
         10        ECHO                                                     ~6
         11        INIT_FCALL                                               'oldgetminprice'
         12        FETCH_DIM_R                                      ~10     !1, 0
         13        SEND_VAL                                                 ~10
         14        FETCH_DIM_R                                      ~11     !1, 1
         15        SEND_VAL                                                 ~11
         16        DO_FCALL                                      0  $12     
         17        ECHO                                                     $12
         18        ECHO                                                     '%0A'
   28    19        ROPE_INIT                                     5  ~16     'new%3A+'
         20        FETCH_DIM_R                                      ~13     !1, 0
         21        ROPE_ADD                                      1  ~16     ~16, ~13
         22        ROPE_ADD                                      2  ~16     ~16, '+-vs-+'
         23        FETCH_DIM_R                                      ~14     !1, 1
         24        ROPE_ADD                                      3  ~16     ~16, ~14
         25        ROPE_END                                      4  ~15     ~16, '+%3D+'
         26        ECHO                                                     ~15
         27        INIT_FCALL                                               'newgetminprice'
         28        SEND_VAR                                                 !1
         29        DO_FCALL                                      0  $19     
         30        ECHO                                                     $19
         31        ECHO                                                     '%0A%0A'
   26    32      > JMP                                                      ->2
         33    >   FE_FREE                                                  $3
   29    34      > RETURN                                                   1

Function oldgetminprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 18
Branch analysis from position: 8
filename:       /in/653oT
function name:  oldGetMinPrice
number of ops:  42
compiled vars:  !0 = $num1, !1 = $num2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        INIT_FCALL                                               'is_numeric'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5      > JMPZ_EX                                          ~3      $2, ->8
          6    >   IS_SMALLER                                       ~4      0, !0
          7        BOOL                                             ~3      ~4
          8    >   BOOL_NOT                                         ~5      ~3
          9      > JMPZ_EX                                          ~5      ~5, ->18
         10    >   INIT_FCALL                                               'is_numeric'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13      > JMPZ_EX                                          ~7      $6, ->16
         14    >   IS_SMALLER                                       ~8      0, !1
         15        BOOL                                             ~7      ~8
         16    >   BOOL_NOT                                         ~9      ~7
         17        BOOL                                             ~5      ~9
         18    > > JMPZ                                                     ~5, ->20
    4    19    > > RETURN                                                   'error'
    6    20    >   CAST                                          5  ~10     !0
         21        ASSIGN                                                   !0, ~10
    7    22        CAST                                          5  ~12     !1
         23        ASSIGN                                                   !1, ~12
    8    24        ROPE_INIT                                     5  ~15     '%28'
         25        ROPE_ADD                                      1  ~15     ~15, !0
         26        ROPE_ADD                                      2  ~15     ~15, '+%26+'
         27        ROPE_ADD                                      3  ~15     ~15, !1
         28        ROPE_END                                      4  ~14     ~15, '%29+'
         29        ECHO                                                     ~14
    9    30        IS_SMALLER_OR_EQUAL                                      !0, 0
         31      > JMPZ                                                     ~18, ->33
   10    32    > > RETURN                                                   !1
   12    33    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         34      > JMPZ                                                     ~19, ->36
   13    35    > > RETURN                                                   !0
   15    36    >   INIT_FCALL                                               'min'
         37        SEND_VAR                                                 !0
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                         $20     
         40      > RETURN                                                   $20
   16    41*     > RETURN                                                   null

End of function oldgetminprice

Function newgetminprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/653oT
function name:  newGetMinPrice
number of ops:  15
compiled vars:  !0 = $nums
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'array_filter'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !0, $2
   19     7        ISSET_ISEMPTY_CV                                         !0
          8      > JMPZ                                                     ~4, ->10
   20     9    > > RETURN                                                   'error'
   22    10    >   INIT_FCALL                                               'min'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13      > RETURN                                                   $5
   23    14*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/653oT
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        CAST                                          5  ~1      !0
          2        IS_SMALLER                                       ~2      0, ~1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

End of function newgetminprice

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.05 ms | 1013 KiB | 18 Q