3v4l.org

run code in 300+ PHP versions simultaneously
<?php // tests testCase("Testing with null", null); testCase("Testing with false", false); testCase("Testing with true", true); testCase("Testing with class", new foreachTest()); testCase("Testing with array", ["key_1" => "val_1", "key_2" => "val_2"]); testCase("Testing with undefined"); // defining the class used in the test case class foreachTest { public $propertyOne = "propertyOneValue"; public $propertyThree = "propertyThreeValue"; private $privateProperty = "privateProperty"; } // test helper function function testCase($description){ // checking for optional argument in a way that allows to "pass in" an "undefined" value $argumentCount = func_num_args(); $inputVariable = $argumentCount > 1 ? func_get_arg(1) : 'noInputDefined' ; if ($inputVariable !== 'noInputDefined') { $undefined = $inputVariable; } try{ // echo test separator with description input echo "\n\n$description (with casting) " . str_repeat("=", 48) . ">>\n\n"; // testing foreach ((array)$undefined as $k => $v) { // potential output echo "$k => $v\n"; } echo "\n\n" . str_repeat("-", 24) . ">> (without casting)\n\n"; // testing without cast foreach ($undefined as $k => $v) { // potential output echo "$k => $v\n"; } }catch(Exception $e){ // test case error $errMessage = $e->getMessage(); echo "Error: $errMessage"; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aO76k
function name:  (null)
number of ops:  26
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL_BY_NAME                                       'testCase'
          1        SEND_VAL_EX                                              'Testing+with+null'
          2        SEND_VAL_EX                                              null
          3        DO_FCALL                                      0          
    5     4        INIT_FCALL_BY_NAME                                       'testCase'
          5        SEND_VAL_EX                                              'Testing+with+false'
          6        SEND_VAL_EX                                              <false>
          7        DO_FCALL                                      0          
    6     8        INIT_FCALL_BY_NAME                                       'testCase'
          9        SEND_VAL_EX                                              'Testing+with+true'
         10        SEND_VAL_EX                                              <true>
         11        DO_FCALL                                      0          
    7    12        INIT_FCALL_BY_NAME                                       'testCase'
         13        SEND_VAL_EX                                              'Testing+with+class'
         14        NEW                                              $3      'foreachTest'
         15        DO_FCALL                                      0          
         16        SEND_VAR_NO_REF_EX                                       $3
         17        DO_FCALL                                      0          
    8    18        INIT_FCALL_BY_NAME                                       'testCase'
         19        SEND_VAL_EX                                              'Testing+with+array'
         20        SEND_VAL_EX                                              <array>
         21        DO_FCALL                                      0          
    9    22        INIT_FCALL_BY_NAME                                       'testCase'
         23        SEND_VAL_EX                                              'Testing+with+undefined'
         24        DO_FCALL                                      0          
   54    25      > RETURN                                                   1

Function testcase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 52
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 52
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 35
Branch analysis from position: 15
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
Branch analysis from position: 15
Found catch point at position: 54
Branch analysis from position: 54
2 jumps found. (Code = 107) Position 1 = 55, Position 2 = -2
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aO76k
function name:  testCase
number of ops:  62
compiled vars:  !0 = $description, !1 = $argumentCount, !2 = $inputVariable, !3 = $undefined, !4 = $v, !5 = $k, !6 = $e, !7 = $errMessage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   22     1        FUNC_NUM_ARGS                                    ~8      
          2        ASSIGN                                                   !1, ~8
   23     3        IS_SMALLER                                               1, !1
          4      > JMPZ                                                     ~10, ->10
          5    >   INIT_FCALL                                               'func_get_arg'
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $11     
          8        QM_ASSIGN                                        ~12     $11
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~12     'noInputDefined'
         11    >   ASSIGN                                                   !2, ~12
   24    12        IS_NOT_IDENTICAL                                         !2, 'noInputDefined'
         13      > JMPZ                                                     ~14, ->15
   25    14    >   ASSIGN                                                   !3, !2
   31    15    >   ROPE_INIT                                     3  ~17     '%0A%0A'
         16        ROPE_ADD                                      1  ~17     ~17, !0
         17        ROPE_END                                      2  ~16     ~17, '+%28with+casting%29+'
         18        INIT_FCALL                                               'str_repeat'
         19        SEND_VAL                                                 '%3D'
         20        SEND_VAL                                                 48
         21        DO_ICALL                                         $19     
         22        CONCAT                                           ~20     ~16, $19
         23        CONCAT                                           ~21     ~20, '%3E%3E%0A%0A'
         24        ECHO                                                     ~21
   34    25        CAST                                          7  ~22     !3
         26      > FE_RESET_R                                       $23     ~22, ->35
         27    > > FE_FETCH_R                                       ~24     $23, !4, ->35
         28    >   ASSIGN                                                   !5, ~24
   36    29        ROPE_INIT                                     4  ~27     !5
         30        ROPE_ADD                                      1  ~27     ~27, '+%3D%3E+'
         31        ROPE_ADD                                      2  ~27     ~27, !4
         32        ROPE_END                                      3  ~26     ~27, '%0A'
         33        ECHO                                                     ~26
   34    34      > JMP                                                      ->27
         35    >   FE_FREE                                                  $23
   39    36        INIT_FCALL                                               'str_repeat'
         37        SEND_VAL                                                 '-'
         38        SEND_VAL                                                 24
         39        DO_ICALL                                         $29     
         40        CONCAT                                           ~30     '%0A%0A', $29
         41        CONCAT                                           ~31     ~30, '%3E%3E+%28without+casting%29%0A%0A'
         42        ECHO                                                     ~31
   42    43      > FE_RESET_R                                       $32     !3, ->52
         44    > > FE_FETCH_R                                       ~33     $32, !4, ->52
         45    >   ASSIGN                                                   !5, ~33
   44    46        ROPE_INIT                                     4  ~36     !5
         47        ROPE_ADD                                      1  ~36     ~36, '+%3D%3E+'
         48        ROPE_ADD                                      2  ~36     ~36, !4
         49        ROPE_END                                      3  ~35     ~36, '%0A'
         50        ECHO                                                     ~35
   42    51      > JMP                                                      ->44
         52    >   FE_FREE                                                  $32
         53      > JMP                                                      ->61
   47    54  E > > CATCH                                       last         'Exception'
   50    55    >   INIT_METHOD_CALL                                         !6, 'getMessage'
         56        DO_FCALL                                      0  $38     
         57        ASSIGN                                                   !7, $38
   51    58        NOP                                                      
         59        FAST_CONCAT                                      ~40     'Error%3A+', !7
         60        ECHO                                                     ~40
   54    61    > > RETURN                                                   null

End of function testcase

Class foreachTest: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
188.5 ms | 1469 KiB | 15 Q