3v4l.org

run code in 500+ 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 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/653oT
function name:  oldGetMinPrice
number of ops:  35
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        FRAMELESS_ICALL_1                is_numeric          ~2      !0
          3      > JMPZ_EX                                              ~2      ~2, ->6
          4    >   IS_SMALLER                                           ~3      0, !0
          5        BOOL                                                 ~2      ~3
          6    >   BOOL_NOT                                             ~4      ~2
          7      > JMPZ_EX                                              ~4      ~4, ->14
          8    >   FRAMELESS_ICALL_1                is_numeric          ~5      !1
          9      > JMPZ_EX                                              ~5      ~5, ->12
         10    >   IS_SMALLER                                           ~6      0, !1
         11        BOOL                                                 ~5      ~6
         12    >   BOOL_NOT                                             ~7      ~5
         13        BOOL                                                 ~4      ~7
         14    > > JMPZ                                                         ~4, ->16
    4    15    > > RETURN                                                       'error'
    6    16    >   CAST                                              5  ~8      !0
         17        ASSIGN                                                       !0, ~8
    7    18        CAST                                              5  ~10     !1
         19        ASSIGN                                                       !1, ~10
    8    20        ROPE_INIT                                         5  ~13     '%28'
         21        ROPE_ADD                                          1  ~13     ~13, !0
         22        ROPE_ADD                                          2  ~13     ~13, '+%26+'
         23        ROPE_ADD                                          3  ~13     ~13, !1
         24        ROPE_END                                          4  ~12     ~13, '%29+'
         25        ECHO                                                         ~12
    9    26        IS_SMALLER_OR_EQUAL                                          !0, 0
         27      > JMPZ                                                         ~16, ->29
   10    28    > > RETURN                                                       !1
   12    29    >   IS_SMALLER_OR_EQUAL                                          !1, 0
         30      > JMPZ                                                         ~17, ->32
   13    31    > > RETURN                                                       !0
   15    32    >   FRAMELESS_ICALL_2                min                 ~18     !0, !1
         33      > RETURN                                                       ~18
   16    34*     > 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:newGetMinPrice():18}
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.5.0


preferences:
172.23 ms | 2113 KiB | 17 Q