3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** Object responsible for echoing debug data **/ class EchoLogger implements SplObserver { public function update(SplSubject $subject) { printf("Rand: %s, Status: %s", $subject->getRand(), $subject->getStatus()); } } /** Object responsible for emailing debug data **/ class EmailLogger implements SplObserver { public function update(SplSubject $subject) { /** Mail your data **/ } } class HttpClientService implements SplSubject { private $observers = array(); public function getRand() { return $this->rand; } public function getStatus() { return $this->status; } public function attach(\SplObserver $observer) { $this->observers[] = $observer; } public function detach(\SplObserver $observer) { if($key = array_search($observer,$this->observers, true)) { unset($this->observers[$key]); } } public function notify() { foreach ($this->observers as $observer) { $observer->update($this); } } public function getServiceStatus() { // -- SNIP -- $this->rand = rand(0, 10); $this->status = ($this->rand >= 5) ? 'success' : 'error'; // -- Snip -- return $this->status; } } $service = new HttpClientService; $service->attach(new EchoLogger); $service->getServiceStatus();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RoFi8
function name:  (null)
number of ops:  14
compiled vars:  !0 = $service
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                            'echologger'
   13     1        DECLARE_CLASS                                            'emaillogger'
   21     2        DECLARE_CLASS                                            'httpclientservice'
   67     3        NEW                                              $1      'HttpClientService'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   69     6        INIT_METHOD_CALL                                         !0, 'attach'
          7        NEW                                              $4      'EchoLogger'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $4
         10        DO_FCALL                                      0          
   71    11        INIT_METHOD_CALL                                         !0, 'getServiceStatus'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Class EchoLogger:
Function update:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RoFi8
function name:  update
number of ops:  11
compiled vars:  !0 = $subject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'printf'
          2        SEND_VAL                                                 'Rand%3A+%25s%2C+Status%3A+%25s'
          3        INIT_METHOD_CALL                                         !0, 'getRand'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        INIT_METHOD_CALL                                         !0, 'getStatus'
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
    9    10      > RETURN                                                   null

End of function update

End of class EchoLogger.

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

End of function update

End of class EmailLogger.

Class HttpClientService:
Function getrand:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RoFi8
function name:  getRand
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'rand'
          1      > RETURN                                                   ~0
   28     2*     > RETURN                                                   null

End of function getrand

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

End of function getstatus

Function attach:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RoFi8
function name:  attach
number of ops:  5
compiled vars:  !0 = $observer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        FETCH_OBJ_W                                      $1      'observers'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   38     4      > RETURN                                                   null

End of function attach

Function detach:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/RoFi8
function name:  detach
number of ops:  12
compiled vars:  !0 = $observer, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        INIT_FCALL                                               'array_search'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~2      'observers'
          4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        ASSIGN                                           ~4      !1, $3
          8      > JMPZ                                                     ~4, ->11
   44     9    >   FETCH_OBJ_UNSET                                  $5      'observers'
         10        UNSET_DIM                                                $5, !1
   46    11    > > RETURN                                                   null

End of function detach

Function notify:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/RoFi8
function name:  notify
number of ops:  10
compiled vars:  !0 = $observer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                      ~1      'observers'
          1      > FE_RESET_R                                       $2      ~1, ->8
          2    > > FE_FETCH_R                                               $2, !0, ->8
   52     3    >   INIT_METHOD_CALL                                         !0, 'update'
          4        FETCH_THIS                                       $3      
          5        SEND_VAR_EX                                              $3
          6        DO_FCALL                                      0          
   50     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $2
   54     9      > RETURN                                                   null

End of function notify

Function getservicestatus:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RoFi8
function name:  getServiceStatus
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 10
          3        DO_ICALL                                         $1      
          4        ASSIGN_OBJ                                               'rand'
          5        OP_DATA                                                  $1
   60     6        FETCH_OBJ_R                                      ~3      'rand'
          7        IS_SMALLER_OR_EQUAL                                      5, ~3
          8      > JMPZ                                                     ~4, ->11
          9    >   QM_ASSIGN                                        ~5      'success'
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~5      'error'
         12    >   ASSIGN_OBJ                                               'status'
         13        OP_DATA                                                  ~5
   63    14        FETCH_OBJ_R                                      ~6      'status'
         15      > RETURN                                                   ~6
   64    16*     > RETURN                                                   null

End of function getservicestatus

End of class HttpClientService.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.25 ms | 1396 KiB | 19 Q