3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class DomainEvent { private static $events = []; /** * @var \DateTime */ private $occurredOn; private function __construct() { static::addEvent($this); $this->occurredOn = new \DateTime(); } public static function trigger(...$args) { $event = new static(); $event->instantiate(...$args); return $event; } abstract protected function instantiate(...$args); private static function addEvent($event) { self::$events[] = $event; } public static function getEvents() { return self::$events; } /** * @return DateTime */ public function getOccurredOn() { return $this->occurredOn; } } class UserRegisteredEvent extends DomainEvent { private $data; protected function instantiate(...$args) { $this->data = $args; } } class User { /** * @var string */ private $username; /** * User constructor. * * @param string $username */ public function __construct($username) { $this->username = $username; UserRegisteredEvent::trigger($this); } /** * @return string */ public function getUsername() { return $this->username; } } $user = new User('Jimmy K. Oak'); $events = DomainEvent::getEvents(); var_dump($events);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  (null)
number of ops:  11
compiled vars:  !0 = $user, !1 = $events
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   NEW                                              $2      'User'
          1        SEND_VAL_EX                                              'Jimmy+K.+Oak'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   86     4        INIT_STATIC_METHOD_CALL                                  'DomainEvent', 'getEvents'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   88     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Class DomainEvent:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_STATIC_METHOD_CALL                                  'addEvent'
          1        FETCH_THIS                                       $0      
          2        SEND_VAR_EX                                              $0
          3        DO_FCALL                                      0          
   15     4        NEW                                              $3      'DateTime'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'occurredOn'
          7        OP_DATA                                                  $3
   16     8      > RETURN                                                   null

End of function __construct

Function trigger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  trigger
number of ops:  10
compiled vars:  !0 = $args, !1 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV_VARIADIC                                    !0      
   20     1        NEW                          static              $2      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   21     4        INIT_METHOD_CALL                                         !1, 'instantiate'
          5        SEND_UNPACK                                              !0
          6        CHECK_UNDEF_ARGS                                         
          7        DO_FCALL                                      1          
   23     8      > RETURN                                                   !1
   24     9*     > RETURN                                                   null

End of function trigger

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

End of function instantiate

Function addevent:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  addEvent
number of ops:  5
compiled vars:  !0 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        FETCH_STATIC_PROP_W          global              $1      'events'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   31     4      > RETURN                                                   null

End of function addevent

Function getevents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  getEvents
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'events'
          1      > RETURN                                                   ~0
   36     2*     > RETURN                                                   null

End of function getevents

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

End of function getoccurredon

End of class DomainEvent.

Class UserRegisteredEvent:
Function instantiate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  instantiate
number of ops:  4
compiled vars:  !0 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV_VARIADIC                                    !0      
   53     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   54     3      > RETURN                                                   null

End of function instantiate

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_STATIC_METHOD_CALL                                  'addEvent'
          1        FETCH_THIS                                       $0      
          2        SEND_VAR_EX                                              $0
          3        DO_FCALL                                      0          
   15     4        NEW                                              $3      'DateTime'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'occurredOn'
          7        OP_DATA                                                  $3
   16     8      > RETURN                                                   null

End of function __construct

Function trigger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  trigger
number of ops:  10
compiled vars:  !0 = $args, !1 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV_VARIADIC                                    !0      
   20     1        NEW                          static              $2      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   21     4        INIT_METHOD_CALL                                         !1, 'instantiate'
          5        SEND_UNPACK                                              !0
          6        CHECK_UNDEF_ARGS                                         
          7        DO_FCALL                                      1          
   23     8      > RETURN                                                   !1
   24     9*     > RETURN                                                   null

End of function trigger

Function addevent:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  addEvent
number of ops:  5
compiled vars:  !0 = $event
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        FETCH_STATIC_PROP_W          global              $1      'events'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   31     4      > RETURN                                                   null

End of function addevent

Function getevents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  getEvents
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'events'
          1      > RETURN                                                   ~0
   36     2*     > RETURN                                                   null

End of function getevents

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

End of function getoccurredon

End of class UserRegisteredEvent.

Class User:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m9F7B
function name:  __construct
number of ops:  8
compiled vars:  !0 = $username
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        ASSIGN_OBJ                                               'username'
          2        OP_DATA                                                  !0
   72     3        INIT_STATIC_METHOD_CALL                                  'UserRegisteredEvent', 'trigger'
          4        FETCH_THIS                                       ~2      
          5        SEND_VAL                                                 ~2
          6        DO_FCALL                                      0          
   73     7      > RETURN                                                   null

End of function __construct

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

End of function getusername

End of class User.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.29 ms | 1408 KiB | 15 Q