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 ($this->queues as $queue) { foreach ($queue as $operation) { yield $operation; } } } protected function getRunGenerator() { $operation_generator = $this->getOperationGenerator(); foreach ($operation_generator as $operation) { yield $operation; } } public function run() { $generator = $this->getRunGenerator(); foreach ($generator as $operation) { var_dump($operation); $operation->run(); } } } function addOperation(\Closure $routine, Queue $queue) { $promise = new Promise(); $operation = new Operation($routine, $promise); $queue->append($operation); return $promise; } addOperation(); $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(); }; addOperation($handle_request, $queue_handler->getQueue('secondary')); }; 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/IKtCY
function name:  (null)
number of ops:  30
compiled vars:  !0 = $queue_handler, !1 = $runtime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  131     0  E >   INIT_FCALL                                               'addoperation'
          1        DO_FCALL                                      0          
  133     2        NEW                                              $3      'QueueHandler'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
  134     5        INIT_METHOD_CALL                                         !0, 'addQueue'
          6        SEND_VAL_EX                                              'main'
          7        NEW                                              $6      'Queue'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0          
  135    11        INIT_METHOD_CALL                                         !0, 'addQueue'
         12        SEND_VAL_EX                                              'secondary'
         13        NEW                                              $9      'Queue'
         14        DO_FCALL                                      0          
         15        SEND_VAR_NO_REF_EX                                       $9
         16        DO_FCALL                                      0          
  137    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIKtCY%3A137%240'
         18        BIND_LEXICAL                                             ~12, !0
         19        ASSIGN                                                   !1, ~12
  146    20        INIT_FCALL                                               'addoperation'
         21        SEND_VAR                                                 !1
         22        INIT_METHOD_CALL                                         !0, 'getQueue'
         23        SEND_VAL_EX                                              'main'
         24        DO_FCALL                                      0  $14     
         25        SEND_VAR                                                 $14
         26        DO_FCALL                                      0          
  149    27        INIT_METHOD_CALL                                         !0, 'run'
         28        DO_FCALL                                      0          
         29      > RETURN                                                   1

Function addoperation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IKtCY
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
-------------------------------------------------------------------------------------
  123     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  124     2        NEW                                              $4      'Promise'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $4
  125     5        NEW                                              $7      'Operation'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $7
  127    10        INIT_METHOD_CALL                                         !1, 'append'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0          
  128    13      > RETURN                                                   !2
  129    14*     > RETURN                                                   null

End of function addoperation

Function %00%7Bclosure%7D%2Fin%2FIKtCY%3A137%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IKtCY
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $promise, !1 = $queue_handler, !2 = $handle_request
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  137     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
  138     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIKtCY%3A138%241'
          3        ASSIGN                                                   !2, ~3
  143     4        INIT_FCALL                                               'addoperation'
          5        SEND_VAR                                                 !2
          6        INIT_METHOD_CALL                                         !1, 'getQueue'
          7        SEND_VAL_EX                                              'secondary'
          8        DO_FCALL                                      0  $5      
          9        SEND_VAR                                                 $5
         10        DO_FCALL                                      0          
  144    11      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIKtCY%3A137%240

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

End of function %00%7Bclosure%7D%2Fin%2FIKtCY%3A138%241

Class Operation:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IKtCY
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/IKtCY
function name:  run
number of ops:  9
compiled vars:  !0 = $routine
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_METHOD_CALL                                         'routine'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   19     3        INIT_DYNAMIC_CALL                                        !0
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $3      'promise'
          6        SEND_FUNC_ARG                                            $3
          7        DO_FCALL                                      0          
   20     8      > 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/IKtCY
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/IKtCY
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/IKtCY
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/IKtCY
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/IKtCY
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/IKtCY
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/IKtCY
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/IKtCY
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 = 13, Position 2 = 20
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 18
Branch analysis from position: 20
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 10
filename:       /in/IKtCY
function name:  getOperationGenerator
number of ops:  22
compiled vars:  !0 = $queues, !1 = $queue, !2 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   GENERATOR_CREATE                                         
   91     1        ASSIGN                                                   !0, <array>
   92     2        FETCH_OBJ_R                                      ~4      'queues'
          3      > FE_RESET_R                                       $5      ~4, ->10
          4    > > FE_FETCH_R                                               $5, !1, ->10
   93     5    >   INIT_METHOD_CALL                                         !1, 'getOperationGenerator'
          6        DO_FCALL                                      0  $7      
          7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  $7
   92     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   96    11        FETCH_OBJ_R                                      ~8      'queues'
         12      > FE_RESET_R                                       $9      ~8, ->20
         13    > > FE_FETCH_R                                               $9, !1, ->20
   97    14    > > FE_RESET_R                                       $10     !1, ->18
         15    > > FE_FETCH_R                                               $10, !2, ->18
   98    16    >   YIELD                                                    !2
   97    17      > JMP                                                      ->15
         18    >   FE_FREE                                                  $10
   96    19      > JMP                                                      ->13
         20    >   FE_FREE                                                  $9
  101    21      > 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/IKtCY
function name:  getRunGenerator
number of ops:  10
compiled vars:  !0 = $operation_generator, !1 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   GENERATOR_CREATE                                         
  105     1        INIT_METHOD_CALL                                         'getOperationGenerator'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
  107     4      > FE_RESET_R                                       $4      !0, ->8
          5    > > FE_FETCH_R                                               $4, !1, ->8
  108     6    >   YIELD                                                    !1
  107     7      > JMP                                                      ->5
          8    >   FE_FREE                                                  $4
  110     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 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/IKtCY
function name:  run
number of ops:  13
compiled vars:  !0 = $generator, !1 = $operation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   INIT_METHOD_CALL                                         'getRunGenerator'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
  116     3      > FE_RESET_R                                       $4      !0, ->11
          4    > > FE_FETCH_R                                               $4, !1, ->11
  117     5    >   INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
  118     8        INIT_METHOD_CALL                                         !1, 'run'
          9        DO_FCALL                                      0          
  116    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $4
  120    12      > RETURN                                                   null

End of function run

End of class QueueHandler.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.65 ms | 1423 KiB | 18 Q