3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Job { private $details; public function __construct($details) { $this->details = $details; } public function requirements() { return $this->details; } } class StackDetector { public static function match($stack, $details) { return strpos($details, $stack) !== false; } } abstract class Handler { protected $successor; public function forwardToSuccessor($job) { if ($this->successor) { $this->successor->handle($job); } } abstract public function handle($job); } class PHPStack extends Handler { public function __construct($successor) { $this->successor = $successor; } public function handle($job) { if (StackDetector::match('PHP', $job->requirements())) { // Notify PHP developers echo 'PHP Stack'; } else { $this->forwardToSuccessor($job); } } } class JavaScriptStack extends Handler { public function __construct($successor) { $this->successor = $successor; } public function handle($job) { if (StackDetector::match('JavaScript', $job->requirements())) { // Notify JavaScript developers echo 'JavaScript Stack'; } else { $this->forwardToSuccessor($job); } } } class JavaStack extends Handler { public function __construct($successor) { $this->successor = $successor; } public function handle($job) { if (StackDetector::match('Java', $job->requirements())) { // Notify Java developers echo 'Java Stack'; } else { $this->forwardToSuccessor($job); } } } class DoNothing extends Handler { public function handle($job) { // Do nothing echo 'The request object is unhandled'; } } // Chain of Job handler objects $doNothing = new DoNothing(); $javaStack = new JavaStack($doNothing); $javaScriptStack = new JavaScriptStack($javaStack); $phpStack = new PHPStack($javaScriptStack); // The request object to be handled $job = new Job('PHP'); // Try changing the value to Python, JavaScript or Java // Starts handling the Job object $phpStack->handle($job);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  (null)
number of ops:  23
compiled vars:  !0 = $doNothing, !1 = $javaStack, !2 = $javaScriptStack, !3 = $phpStack, !4 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   NEW                                              $5      'DoNothing'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
   87     3        NEW                                              $8      'JavaStack'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $8
   88     7        NEW                                              $11     'JavaScriptStack'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $11
   89    11        NEW                                              $14     'PHPStack'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !3, $14
   92    15        NEW                                              $17     'Job'
         16        SEND_VAL_EX                                              'PHP'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !4, $17
   95    19        INIT_METHOD_CALL                                         !3, 'handle'
         20        SEND_VAR_EX                                              !4
         21        DO_FCALL                                      0          
         22      > RETURN                                                   1

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

End of function __construct

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

End of function requirements

End of class Job.

Class StackDetector:
Function match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  match
number of ops:  9
compiled vars:  !0 = $stack, !1 = $details
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        TYPE_CHECK                                  1018  ~3      $2
          7      > RETURN                                                   ~3
   18     8*     > RETURN                                                   null

End of function match

End of class StackDetector.

Class Handler:
Function forwardtosuccessor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hF35E
function name:  forwardToSuccessor
number of ops:  8
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'successor'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   FETCH_OBJ_R                                      ~2      'successor'
          4        INIT_METHOD_CALL                                         ~2, 'handle'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7    > > RETURN                                                   null

End of function forwardtosuccessor

Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  handle
number of ops:  2
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function handle

End of class Handler.

Class PHPStack:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  __construct
number of ops:  4
compiled vars:  !0 = $successor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        ASSIGN_OBJ                                               'successor'
          2        OP_DATA                                                  !0
   36     3      > RETURN                                                   null

End of function __construct

Function handle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  handle
number of ops:  14
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        INIT_STATIC_METHOD_CALL                                  'StackDetector', 'match'
          2        SEND_VAL                                                 'PHP'
          3        INIT_METHOD_CALL                                         !0, 'requirements'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_FCALL                                      0  $2      
          7      > JMPZ                                                     $2, ->10
   41     8    >   ECHO                                                     'PHP+Stack'
   39     9      > JMP                                                      ->13
   43    10    >   INIT_METHOD_CALL                                         'forwardToSuccessor'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   45    13    > > RETURN                                                   null

End of function handle

Function forwardtosuccessor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hF35E
function name:  forwardToSuccessor
number of ops:  8
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'successor'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   FETCH_OBJ_R                                      ~2      'successor'
          4        INIT_METHOD_CALL                                         ~2, 'handle'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7    > > RETURN                                                   null

End of function forwardtosuccessor

End of class PHPStack.

Class JavaScriptStack:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  __construct
number of ops:  4
compiled vars:  !0 = $successor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        ASSIGN_OBJ                                               'successor'
          2        OP_DATA                                                  !0
   51     3      > RETURN                                                   null

End of function __construct

Function handle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  handle
number of ops:  14
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        INIT_STATIC_METHOD_CALL                                  'StackDetector', 'match'
          2        SEND_VAL                                                 'JavaScript'
          3        INIT_METHOD_CALL                                         !0, 'requirements'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_FCALL                                      0  $2      
          7      > JMPZ                                                     $2, ->10
   56     8    >   ECHO                                                     'JavaScript+Stack'
   54     9      > JMP                                                      ->13
   58    10    >   INIT_METHOD_CALL                                         'forwardToSuccessor'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   60    13    > > RETURN                                                   null

End of function handle

Function forwardtosuccessor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hF35E
function name:  forwardToSuccessor
number of ops:  8
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'successor'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   FETCH_OBJ_R                                      ~2      'successor'
          4        INIT_METHOD_CALL                                         ~2, 'handle'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7    > > RETURN                                                   null

End of function forwardtosuccessor

End of class JavaScriptStack.

Class JavaStack:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  __construct
number of ops:  4
compiled vars:  !0 = $successor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   65     1        ASSIGN_OBJ                                               'successor'
          2        OP_DATA                                                  !0
   66     3      > RETURN                                                   null

End of function __construct

Function handle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  handle
number of ops:  14
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   69     1        INIT_STATIC_METHOD_CALL                                  'StackDetector', 'match'
          2        SEND_VAL                                                 'Java'
          3        INIT_METHOD_CALL                                         !0, 'requirements'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_FCALL                                      0  $2      
          7      > JMPZ                                                     $2, ->10
   71     8    >   ECHO                                                     'Java+Stack'
   69     9      > JMP                                                      ->13
   73    10    >   INIT_METHOD_CALL                                         'forwardToSuccessor'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   75    13    > > RETURN                                                   null

End of function handle

Function forwardtosuccessor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hF35E
function name:  forwardToSuccessor
number of ops:  8
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'successor'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   FETCH_OBJ_R                                      ~2      'successor'
          4        INIT_METHOD_CALL                                         ~2, 'handle'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7    > > RETURN                                                   null

End of function forwardtosuccessor

End of class JavaStack.

Class DoNothing:
Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hF35E
function name:  handle
number of ops:  3
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   81     1        ECHO                                                     'The+request+object+is+unhandled'
   82     2      > RETURN                                                   null

End of function handle

Function forwardtosuccessor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hF35E
function name:  forwardToSuccessor
number of ops:  8
compiled vars:  !0 = $job
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'successor'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   FETCH_OBJ_R                                      ~2      'successor'
          4        INIT_METHOD_CALL                                         ~2, 'handle'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7    > > RETURN                                                   null

End of function forwardtosuccessor

End of class DoNothing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.67 ms | 1453 KiB | 14 Q