3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function getCollectionParentIDFromChildID($cID) { if(is_numeric($cID)) { if($cID > 1) { return '1'; } if($cID == 1) { return '0'; } } return null; } function populateParentIDArray_current($cID) { global $cParentIDArray; $cParentID = getCollectionParentIDFromChildID($cID); if($cParentID > -1) { if(!in_array($cParentID, $cParentIDArray)) { $cParentIDArray[] = $cParentID; } populateParentIDArray_current($cParentID); } } function populateParentIDArray_new($cID) { global $cParentIDArray; $cParentID = getCollectionParentIDFromChildID($cID); if(is_numeric($cParentID)) { if(!in_array($cParentID, $cParentIDArray)) { $cParentIDArray[] = $cParentID; } if($cParentID > 0) { populateParentIDArray_new($cParentID); } } } function runTest($cID) { global $cParentIDArray; echo "Test case for "; var_dump($cID); $cParentIDArray = array(); populateParentIDArray_current($cID); ob_start(); var_dump($cParentIDArray); $current = ob_get_contents(); ob_end_clean(); $cParentIDArray = array(); populateParentIDArray_new($cID); ob_start(); var_dump($cParentIDArray); $new = ob_get_contents(); ob_end_clean(); if($current === $new) { echo "Passed. Result: ", $current; } else { echo "###ERROR\nCURRENT: ", $current, "\nNEW: ", $new, "\n"; } echo "\n\n"; } runTest('3'); runTest('1'); runTest('0'); runTest(3); runTest(1); runTest(0); runTest(null); runTest('');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XUPI3
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   63     3        INIT_FCALL                                               'runtest'
          4        SEND_VAL                                                 '3'
          5        DO_FCALL                                      0          
   64     6        INIT_FCALL                                               'runtest'
          7        SEND_VAL                                                 '1'
          8        DO_FCALL                                      0          
   65     9        INIT_FCALL                                               'runtest'
         10        SEND_VAL                                                 '0'
         11        DO_FCALL                                      0          
   66    12        INIT_FCALL                                               'runtest'
         13        SEND_VAL                                                 3
         14        DO_FCALL                                      0          
   67    15        INIT_FCALL                                               'runtest'
         16        SEND_VAL                                                 1
         17        DO_FCALL                                      0          
   68    18        INIT_FCALL                                               'runtest'
         19        SEND_VAL                                                 0
         20        DO_FCALL                                      0          
   69    21        INIT_FCALL                                               'runtest'
         22        SEND_VAL                                                 null
         23        DO_FCALL                                      0          
   70    24        INIT_FCALL                                               'runtest'
         25        SEND_VAL                                                 ''
         26        DO_FCALL                                      0          
         27      > RETURN                                                   1

Function getcollectionparentidfromchildid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/XUPI3
function name:  getCollectionParentIDFromChildID
number of ops:  13
compiled vars:  !0 = $cID
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ                                                     $1, ->11
    6     5    >   IS_SMALLER                                               1, !0
          6      > JMPZ                                                     ~2, ->8
    7     7    > > RETURN                                                   '1'
    9     8    >   IS_EQUAL                                                 !0, 1
          9      > JMPZ                                                     ~3, ->11
   10    10    > > RETURN                                                   '0'
   13    11    > > RETURN                                                   null
   14    12*     > RETURN                                                   null

End of function getcollectionparentidfromchildid

Function populateparentidarray_current:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 19
filename:       /in/XUPI3
function name:  populateParentIDArray_current
number of ops:  20
compiled vars:  !0 = $cID, !1 = $cParentIDArray, !2 = $cParentID
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        BIND_GLOBAL                                              !1, 'cParentIDArray'
   18     2        INIT_FCALL                                               'getcollectionparentidfromchildid'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !2, $3
   19     6        IS_SMALLER                                               -1, !2
          7      > JMPZ                                                     ~5, ->19
   20     8    >   INIT_FCALL                                               'in_array'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        BOOL_NOT                                         ~7      $6
         13      > JMPZ                                                     ~7, ->16
   21    14    >   ASSIGN_DIM                                               !1
         15        OP_DATA                                                  !2
   23    16    >   INIT_FCALL_BY_NAME                                       'populateParentIDArray_current'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
   25    19    > > RETURN                                                   null

End of function populateparentidarray_current

Function populateparentidarray_new:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 18
Branch analysis from position: 23
filename:       /in/XUPI3
function name:  populateParentIDArray_new
number of ops:  24
compiled vars:  !0 = $cID, !1 = $cParentIDArray, !2 = $cParentID
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        BIND_GLOBAL                                              !1, 'cParentIDArray'
   29     2        INIT_FCALL                                               'getcollectionparentidfromchildid'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !2, $3
   30     6        INIT_FCALL                                               'is_numeric'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $5      
          9      > JMPZ                                                     $5, ->23
   31    10    >   INIT_FCALL                                               'in_array'
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $6      
         14        BOOL_NOT                                         ~7      $6
         15      > JMPZ                                                     ~7, ->18
   32    16    >   ASSIGN_DIM                                               !1
         17        OP_DATA                                                  !2
   34    18    >   IS_SMALLER                                               0, !2
         19      > JMPZ                                                     ~9, ->23
   35    20    >   INIT_FCALL_BY_NAME                                       'populateParentIDArray_new'
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
   38    23    > > RETURN                                                   null

End of function populateparentidarray_new

Function runtest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XUPI3
function name:  runTest
number of ops:  46
compiled vars:  !0 = $cID, !1 = $cParentIDArray, !2 = $current, !3 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        BIND_GLOBAL                                              !1, 'cParentIDArray'
   42     2        ECHO                                                     'Test+case+for+'
          3        INIT_FCALL                                               'var_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   43     6        ASSIGN                                                   !1, <array>
   44     7        INIT_FCALL                                               'populateparentidarray_current'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0          
   45    10        INIT_FCALL                                               'ob_start'
         11        DO_ICALL                                                 
   46    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
   47    15        INIT_FCALL                                               'ob_get_contents'
         16        DO_ICALL                                         $9      
         17        ASSIGN                                                   !2, $9
   48    18        INIT_FCALL                                               'ob_end_clean'
         19        DO_ICALL                                                 
   49    20        ASSIGN                                                   !1, <array>
   50    21        INIT_FCALL                                               'populateparentidarray_new'
         22        SEND_VAR                                                 !0
         23        DO_FCALL                                      0          
   51    24        INIT_FCALL                                               'ob_start'
         25        DO_ICALL                                                 
   52    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                                 
   53    29        INIT_FCALL                                               'ob_get_contents'
         30        DO_ICALL                                         $16     
         31        ASSIGN                                                   !3, $16
   54    32        INIT_FCALL                                               'ob_end_clean'
         33        DO_ICALL                                                 
   55    34        IS_IDENTICAL                                             !2, !3
         35      > JMPZ                                                     ~19, ->39
   56    36    >   ECHO                                                     'Passed.+Result%3A+'
         37        ECHO                                                     !2
         38      > JMP                                                      ->44
   59    39    >   ECHO                                                     '%23%23%23ERROR%0ACURRENT%3A+'
         40        ECHO                                                     !2
         41        ECHO                                                     '%0ANEW%3A+'
         42        ECHO                                                     !3
         43        ECHO                                                     '%0A'
   61    44    >   ECHO                                                     '%0A%0A'
   62    45      > RETURN                                                   null

End of function runtest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.96 ms | 1411 KiB | 39 Q