3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* A tasks job is to count from 0 to $limit */ class Task { public function __construct($limit) { $this->limit = ($limit + 1) * 100; } public function doWork() { $this->position++; } public function hasWork() { return $this->position <= $this->limit; } public function getPosition() { return $this->position; } private $position = 0; private $limit = 0; } /* create three tasks */ $tasks[] = new Task(0); $tasks[] = new Task(1); $tasks[] = new Task(3); /* do some work */ function work($tasks) { foreach ($tasks as $task) if ($task->hasWork()) $task->doWork(); } /* detect more work to do */ function finished($tasks) { foreach ($tasks as $task) { if ($task->hasWork()) return false; } return true; } /* helper for printing positions */ function positions($tasks) { $positions = array(); foreach ($tasks as $task) { $positions[] = $task->hasWork() ? $task->getPosition() : "-"; } return $positions; } /* execute tasks asynchronously */ while (!finished($tasks)) { vprintf( "% 4s % 4s % 4s\n", positions($tasks)); work($tasks); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 16
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 16
Branch analysis from position: 31
Branch analysis from position: 16
filename:       /in/XDfSs
function name:  (null)
number of ops:  32
compiled vars:  !0 = $tasks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $2      'Task'
          1        SEND_VAL_EX                                              0
          2        DO_FCALL                                      0          
          3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  $2
   27     5        NEW                                              $5      'Task'
          6        SEND_VAL_EX                                              1
          7        DO_FCALL                                      0          
          8        ASSIGN_DIM                                               !0
          9        OP_DATA                                                  $5
   28    10        NEW                                              $8      'Task'
         11        SEND_VAL_EX                                              3
         12        DO_FCALL                                      0          
         13        ASSIGN_DIM                                               !0
         14        OP_DATA                                                  $8
   59    15      > JMP                                                      ->26
   60    16    >   INIT_FCALL                                               'vprintf'
   61    17        SEND_VAL                                                 '%25+4s+%25+4s+%25+4s%0A'
         18        INIT_FCALL                                               'positions'
         19        SEND_VAR                                                 !0
         20        DO_FCALL                                      0  $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                                 
   62    23        INIT_FCALL                                               'work'
         24        SEND_VAR                                                 !0
         25        DO_FCALL                                      0          
   59    26    >   INIT_FCALL                                               'finished'
         27        SEND_VAR                                                 !0
         28        DO_FCALL                                      0  $13     
         29        BOOL_NOT                                         ~14     $13
         30      > JMPNZ                                                    ~14, ->16
   64    31    > > RETURN                                                   1

Function work:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/XDfSs
function name:  work
number of ops:  11
compiled vars:  !0 = $tasks, !1 = $task
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1      > FE_RESET_R                                       $2      !0, ->9
          2    > > FE_FETCH_R                                               $2, !1, ->9
   33     3    >   INIT_METHOD_CALL                                         !1, 'hasWork'
          4        DO_FCALL                                      0  $3      
          5      > JMPZ                                                     $3, ->8
   34     6    >   INIT_METHOD_CALL                                         !1, 'doWork'
          7        DO_FCALL                                      0          
   32     8    > > JMP                                                      ->2
          9    >   FE_FREE                                                  $2
   35    10      > RETURN                                                   null

End of function work

Function finished:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/XDfSs
function name:  finished
number of ops:  12
compiled vars:  !0 = $tasks, !1 = $task
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1      > FE_RESET_R                                       $2      !0, ->9
          2    > > FE_FETCH_R                                               $2, !1, ->9
   40     3    >   INIT_METHOD_CALL                                         !1, 'hasWork'
          4        DO_FCALL                                      0  $3      
          5      > JMPZ                                                     $3, ->8
   41     6    >   FE_FREE                                                  $2
          7      > RETURN                                                   <false>
   39     8    > > JMP                                                      ->2
          9    >   FE_FREE                                                  $2
   44    10      > RETURN                                                   <true>
   45    11*     > RETURN                                                   null

End of function finished

Function positions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/XDfSs
function name:  positions
number of ops:  18
compiled vars:  !0 = $tasks, !1 = $positions, !2 = $task
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1        ASSIGN                                                   !1, <array>
   50     2      > FE_RESET_R                                       $4      !0, ->15
          3    > > FE_FETCH_R                                               $4, !2, ->15
   52     4    >   INIT_METHOD_CALL                                         !2, 'hasWork'
          5        DO_FCALL                                      0  $6      
          6      > JMPZ                                                     $6, ->11
   53     7    >   INIT_METHOD_CALL                                         !2, 'getPosition'
          8        DO_FCALL                                      0  $7      
          9        QM_ASSIGN                                        ~8      $7
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~8      '-'
   51    12    >   ASSIGN_DIM                                               !1
   53    13        OP_DATA                                                  ~8
   50    14      > JMP                                                      ->3
         15    >   FE_FREE                                                  $4
   55    16      > RETURN                                                   !1
   56    17*     > RETURN                                                   null

End of function positions

Class Task:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XDfSs
function name:  __construct
number of ops:  6
compiled vars:  !0 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ADD                                              ~2      !0, 1
          2        MUL                                              ~3      ~2, 100
          3        ASSIGN_OBJ                                               'limit'
          4        OP_DATA                                                  ~3
    7     5      > RETURN                                                   null

End of function __construct

Function dowork:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XDfSs
function name:  doWork
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   PRE_INC_OBJ                                              'position'
   11     1      > RETURN                                                   null

End of function dowork

Function haswork:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XDfSs
function name:  hasWork
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1        FETCH_OBJ_R                                      ~1      'limit'
          2        IS_SMALLER_OR_EQUAL                              ~2      ~0, ~1
          3      > RETURN                                                   ~2
   15     4*     > RETURN                                                   null

End of function haswork

Function getposition:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XDfSs
function name:  getPosition
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1      > RETURN                                                   ~0
   19     2*     > RETURN                                                   null

End of function getposition

End of class Task.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.37 ms | 1402 KiB | 18 Q