3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Operation { protected $routine; protected $promise; public function __construct(\Closure $routine, $promise) { $this->routine = $routine; $this->promise = $promise; } public function run() { $routine = $this->routine; $routine($this->promise); } public function getPromise() { return $this->promise; } } class Promise { protected $successClosure; protected $failClosure; public function fulfill(...$args) { $closure = $this->successClosure; $closure(...$args); } public function reject(...$args) { $closure = $this->failClosure; $closure(...$args); } public function then(\Closure $success, \Closure $fail) { $this->successClosure = $success; $this->failClosure = $fail; } } class Queue { protected $queue = []; public function append(Operation $operation) { $this->queue[] = $operation; } public function getOperationGenerator() { foreach ($this->queue as $operation) { yield $operation; } } } class QueueHandler { protected $queues = []; public function addQueue($handle, Queue $queue) { $this->queues[$handle] = $queue; } public function getQueue($handle, $defualt=null) { return isset($this->queues[$handle]) ? $this->queues[$handle] : $default; } protected function getOperationGenerator() { $queues = []; foreach ($this->queues as $queue) { $queues[] = $queue->getOperationGenerator(); } foreach ($queues as $queue) { yield from $queue; } } protected function getRunGenerator() { $operation_generator = $this->getOperationGenerator(); foreach ($operation_generator as $operation) { yield $operation; } } public function run() { $generator = $this->getRunGenerator(); foreach ($generator as $operation) { $operation->run(); } } } function addOperation(\Closure $routine, Queue $queue) { $promise = new Promise(); $operation = new Operation($routine, $promise); $queue->append($operation); return $promise; } $queue_handler = new QueueHandler(); $queue_handler->addQueue('main', new Queue()); $queue_handler->addQueue('secondary', new Queue()); $runtime = function(Promise $promise) use ($queue_handler) { $handle_request = function(Promise $promise) { var_dump('handled request'); $promise->fulfill(); }; $request_promise = addOperation($handle_request, $queue_handler->getQueue('secondary')); $request_promise->then(function() { die('Regular shutdown'); }, function() { die('Error!'); }); }; addOperation($runtime, $queue_handler->getQueue('main')); $queue_handler->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  (null)
number of ops:  28
compiled vars:  !0 = $queue_handler, !1 = $runtime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     0  E >   NEW                                              $2      'QueueHandler'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
  129     3        INIT_METHOD_CALL                                         !0, 'addQueue'
          4        SEND_VAL_EX                                              'main'
          5        NEW                                              $5      'Queue'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $5
          8        DO_FCALL                                      0          
  130     9        INIT_METHOD_CALL                                         !0, 'addQueue'
         10        SEND_VAL_EX                                              'secondary'
         11        NEW                                              $8      'Queue'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $8
         14        DO_FCALL                                      0          
  132    15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgtNEr%3A132%240'
         16        BIND_LEXICAL                                             ~11, !0
         17        ASSIGN                                                   !1, ~11
  146    18        INIT_FCALL                                               'addoperation'
         19        SEND_VAR                                                 !1
         20        INIT_METHOD_CALL                                         !0, 'getQueue'
         21        SEND_VAL_EX                                              'main'
         22        DO_FCALL                                      0  $13     
         23        SEND_VAR                                                 $13
         24        DO_FCALL                                      0          
  149    25        INIT_METHOD_CALL                                         !0, 'run'
         26        DO_FCALL                                      0          
         27      > RETURN                                                   1

Function addoperation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  addOperation
number of ops:  15
compiled vars:  !0 = $routine, !1 = $queue, !2 = $promise, !3 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  120     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  121     2        NEW                                              $4      'Promise'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $4
  122     5        NEW                                              $7      'Operation'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $7
  124    10        INIT_METHOD_CALL                                         !1, 'append'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0          
  125    13      > RETURN                                                   !2
  126    14*     > RETURN                                                   null

End of function addoperation

Function %00%7Bclosure%7D%2Fin%2FgtNEr%3A132%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $promise, !1 = $queue_handler, !2 = $handle_request, !3 = $request_promise
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  132     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
  133     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgtNEr%3A133%241'
          3        ASSIGN                                                   !2, ~4
  138     4        INIT_FCALL                                               'addoperation'
          5        SEND_VAR                                                 !2
          6        INIT_METHOD_CALL                                         !1, 'getQueue'
          7        SEND_VAL_EX                                              'secondary'
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !3, $7
  139    12        INIT_METHOD_CALL                                         !3, 'then'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgtNEr%3A139%242'
  141    14        SEND_VAL_EX                                              ~9
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgtNEr%3A141%243'
  143    16        SEND_VAL_EX                                              ~10
         17        DO_FCALL                                      0          
  144    18      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgtNEr%3A132%240

Function %00%7Bclosure%7D%2Fin%2FgtNEr%3A133%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $promise
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  133     0  E >   RECV                                             !0      
  134     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAL                                                 'handled+request'
          3        DO_ICALL                                                 
  135     4        INIT_METHOD_CALL                                         !0, 'fulfill'
          5        DO_FCALL                                      0          
  136     6      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgtNEr%3A133%241

Function %00%7Bclosure%7D%2Fin%2FgtNEr%3A139%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/gtNEr
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  140     0  E > > EXIT                                                     'Regular+shutdown'
  141     1*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgtNEr%3A139%242

Function %00%7Bclosure%7D%2Fin%2FgtNEr%3A141%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/gtNEr
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  142     0  E > > EXIT                                                     'Error%21'
  143     1*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgtNEr%3A141%243

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

End of function __construct

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  run
number of ops:  8
compiled vars:  !0 = $routine
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                      ~1      'routine'
          1        ASSIGN                                                   !0, ~1
   19     2        INIT_DYNAMIC_CALL                                        !0
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $3      'promise'
          5        SEND_FUNC_ARG                                            $3
          6        DO_FCALL                                      0          
   20     7      > RETURN                                                   null

End of function run

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

End of function getpromise

End of class Operation.

Class Promise:
Function fulfill:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  fulfill
number of ops:  8
compiled vars:  !0 = $args, !1 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV_VARIADIC                                    !0      
   38     1        FETCH_OBJ_R                                      ~2      'successClosure'
          2        ASSIGN                                                   !1, ~2
   39     3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_UNPACK                                              !0
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      1          
   40     7      > RETURN                                                   null

End of function fulfill

Function reject:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  reject
number of ops:  8
compiled vars:  !0 = $args, !1 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV_VARIADIC                                    !0      
   44     1        FETCH_OBJ_R                                      ~2      'failClosure'
          2        ASSIGN                                                   !1, ~2
   45     3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_UNPACK                                              !0
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      1          
   46     7      > RETURN                                                   null

End of function reject

Function then:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  then
number of ops:  7
compiled vars:  !0 = $success, !1 = $fail
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        ASSIGN_OBJ                                               'successClosure'
          3        OP_DATA                                                  !0
   51     4        ASSIGN_OBJ                                               'failClosure'
          5        OP_DATA                                                  !1
   52     6      > RETURN                                                   null

End of function then

End of class Promise.

Class Queue:
Function append:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  append
number of ops:  5
compiled vars:  !0 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        FETCH_OBJ_W                                      $1      'queue'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   63     4      > RETURN                                                   null

End of function append

Function getoperationgenerator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
filename:       /in/gtNEr
function name:  getOperationGenerator
number of ops:  8
compiled vars:  !0 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   GENERATOR_CREATE                                         
   67     1        FETCH_OBJ_R                                      ~1      'queue'
          2      > FE_RESET_R                                       $2      ~1, ->6
          3    > > FE_FETCH_R                                               $2, !0, ->6
   68     4    >   YIELD                                                    !0
   67     5      > JMP                                                      ->3
          6    >   FE_FREE                                                  $2
   70     7      > GENERATOR_RETURN                                         

End of function getoperationgenerator

End of class Queue.

Class QueueHandler:
Function addqueue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  addQueue
number of ops:  6
compiled vars:  !0 = $handle, !1 = $queue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   81     2        FETCH_OBJ_W                                      $2      'queues'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   82     5      > RETURN                                                   null

End of function addqueue

Function getqueue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtNEr
function name:  getQueue
number of ops:  12
compiled vars:  !0 = $handle, !1 = $defualt, !2 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   86     2        FETCH_OBJ_IS                                     ~3      'queues'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~3, !0
          4      > JMPZ                                                     ~4, ->9
          5    >   FETCH_OBJ_R                                      ~5      'queues'
          6        FETCH_DIM_R                                      ~6      ~5, !0
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~7      !2
         10    > > RETURN                                                   ~7
   87    11*     > RETURN                                                   null

End of function getqueue

Function getoperationgenerator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 16
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 10
filename:       /in/gtNEr
function name:  getOperationGenerator
number of ops:  18
compiled vars:  !0 = $queues, !1 = $queue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   GENERATOR_CREATE                                         
   91     1        ASSIGN                                                   !0, <array>
   92     2        FETCH_OBJ_R                                      ~3      'queues'
          3      > FE_RESET_R                                       $4      ~3, ->10
          4    > > FE_FETCH_R                                               $4, !1, ->10
   93     5    >   INIT_METHOD_CALL                                         !1, 'getOperationGenerator'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  $6
   92     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $4
   96    11      > FE_RESET_R                                       $7      !0, ->16
         12    > > FE_FETCH_R                                               $7, !1, ->16
   97    13    >   YIELD_FROM                                       ~8      !1
         14        FREE                                                     ~8
   96    15      > JMP                                                      ->12
         16    >   FE_FREE                                                  $7
   99    17      > GENERATOR_RETURN                                         

End of function getoperationgenerator

Function getrungenerator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
filename:       /in/gtNEr
function name:  getRunGenerator
number of ops:  10
compiled vars:  !0 = $operation_generator, !1 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   GENERATOR_CREATE                                         
  103     1        INIT_METHOD_CALL                                         'getOperationGenerator'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
  105     4      > FE_RESET_R                                       $4      !0, ->8
          5    > > FE_FETCH_R                                               $4, !1, ->8
  106     6    >   YIELD                                                    !1
  105     7      > JMP                                                      ->5
          8    >   FE_FREE                                                  $4
  108     9      > GENERATOR_RETURN                                         

End of function getrungenerator

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/gtNEr
function name:  run
number of ops:  10
compiled vars:  !0 = $generator, !1 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   INIT_METHOD_CALL                                         'getRunGenerator'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
  114     3      > FE_RESET_R                                       $4      !0, ->8
          4    > > FE_FETCH_R                                               $4, !1, ->8
  115     5    >   INIT_METHOD_CALL                                         !1, 'run'
          6        DO_FCALL                                      0          
  114     7      > JMP                                                      ->4
          8    >   FE_FREE                                                  $4
  117     9      > RETURN                                                   null

End of function run

End of class QueueHandler.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.03 ms | 1423 KiB | 17 Q