3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Notification { public $is_notifyable; public $children = []; } function mergeNotifications(Notification ... $notifications) : array { $result = []; foreach ($notifications as $notification) { // Can no longer be "empty" // if (empty($notification)) continue; // is_notifyable is now a promise that your interface made: if ($notification->is_notifyable) { $result[] = $notification; } else { // flatten the notifications recursively: foreach(mergeNotifications(...$notification->children) as $child) { $result[] = $child; } } } return $result; } $arr = [ new Notification(), new Notification(), ]; var_dump(mergeNotifications(...$arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LVppN
function name:  (null)
number of ops:  15
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $1      'Notification'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1
   35     3        NEW                                              $4      'Notification'
          4        DO_FCALL                                      0          
          5        ADD_ARRAY_ELEMENT                                ~3      $4
   33     6        ASSIGN                                                   !0, ~3
   38     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'mergenotifications'
          9        SEND_UNPACK                                              !0
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1  $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function mergenotifications:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LVppN
function name:  mergeNotifications
number of ops:  26
compiled vars:  !0 = $notifications, !1 = $result, !2 = $notification, !3 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_VARIADIC                                    !0      
   10     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $5      !0, ->21
          3    > > FE_FETCH_R                                               $5, !2, ->21
   17     4    >   FETCH_OBJ_R                                      ~6      !2, 'is_notifyable'
          5      > JMPZ                                                     ~6, ->9
   18     6    >   ASSIGN_DIM                                               !1
          7        OP_DATA                                                  !2
          8      > JMP                                                      ->20
   23     9    >   INIT_FCALL_BY_NAME                                       'mergeNotifications'
         10        FETCH_OBJ_R                                      ~8      !2, 'children'
         11        SEND_UNPACK                                              ~8
         12        CHECK_UNDEF_ARGS                                         
         13        DO_FCALL                                      1  $9      
         14      > FE_RESET_R                                       $10     $9, ->19
         15    > > FE_FETCH_R                                               $10, !3, ->19
   25    16    >   ASSIGN_DIM                                               !1
         17        OP_DATA                                                  !3
   23    18      > JMP                                                      ->15
         19    >   FE_FREE                                                  $10
   12    20    > > JMP                                                      ->3
         21    >   FE_FREE                                                  $5
   30    22        VERIFY_RETURN_TYPE                                       !1
         23      > RETURN                                                   !1
   31    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function mergenotifications

Class Notification: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.59 ms | 1407 KiB | 16 Q