3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ServiceLocator { public function getBuzzer() { return new Buzzer; } } class Buzzer { public function __construct() { sleep(5); } public function buzz() { echo "Buzz!"; } } class BuzzerProxy extends Buzzer { protected $sl; protected $initialized; protected $instance; public function __construct(ServiceLocator $sl) { $this->sl = $sl; } private function initialize() { $this->instance = $this->sl->getBuzzer(); $this->initialized = true; } public function buzz() { if (!$this->initialized) {$this->initialize();} return $this->instance->buzz(); } } $now = microtime(); $sl = new ServiceLocator; echo "Created service locator in " . microtime() - $now . "ms\n"; $now = microtime(); $proxy = new BuzzerProxy($sl); echo "Created buzzer proxy in " . microtime() - $now . "ms\n"; $now = microtime(); $proxy->buzz(); echo "Buzzed after " . microtime() - $now . "ms\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7J10A
function name:  (null)
number of ops:  37
compiled vars:  !0 = $now, !1 = $sl, !2 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   INIT_FCALL                                               'microtime'
          1        DO_ICALL                                         $3      
          2        ASSIGN                                                   !0, $3
   49     3        NEW                                              $5      'ServiceLocator'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   50     6        INIT_FCALL                                               'microtime'
          7        DO_ICALL                                         $8      
          8        SUB                                              ~9      $8, !0
          9        CONCAT                                           ~10     'Created+service+locator+in+', ~9
         10        CONCAT                                           ~11     ~10, 'ms%0A'
         11        ECHO                                                     ~11
   52    12        INIT_FCALL                                               'microtime'
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !0, $12
   53    15        NEW                                              $14     'BuzzerProxy'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $14
   54    19        INIT_FCALL                                               'microtime'
         20        DO_ICALL                                         $17     
         21        SUB                                              ~18     $17, !0
         22        CONCAT                                           ~19     'Created+buzzer+proxy+in+', ~18
         23        CONCAT                                           ~20     ~19, 'ms%0A'
         24        ECHO                                                     ~20
   56    25        INIT_FCALL                                               'microtime'
         26        DO_ICALL                                         $21     
         27        ASSIGN                                                   !0, $21
   57    28        INIT_METHOD_CALL                                         !2, 'buzz'
         29        DO_FCALL                                      0          
   58    30        INIT_FCALL                                               'microtime'
         31        DO_ICALL                                         $24     
         32        SUB                                              ~25     $24, !0
         33        CONCAT                                           ~26     'Buzzed+after+', ~25
         34        CONCAT                                           ~27     ~26, 'ms%0A'
         35        ECHO                                                     ~27
         36      > RETURN                                                   1

Class ServiceLocator:
Function getbuzzer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7J10A
function name:  getBuzzer
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   NEW                                              $0      'Buzzer'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
    7     3*     > RETURN                                                   null

End of function getbuzzer

End of class ServiceLocator.

Class Buzzer:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7J10A
function name:  __construct
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'sleep'
          1        SEND_VAL                                                 5
          2        DO_ICALL                                                 
   15     3      > RETURN                                                   null

End of function __construct

Function buzz:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7J10A
function name:  buzz
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ECHO                                                     'Buzz%21'
   20     1      > RETURN                                                   null

End of function buzz

End of class Buzzer.

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

End of function __construct

Function initialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7J10A
function name:  initialize
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                      ~1      'sl'
          1        INIT_METHOD_CALL                                         ~1, 'getBuzzer'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_OBJ                                               'instance'
          4        OP_DATA                                                  $2
   37     5        ASSIGN_OBJ                                               'initialized'
          6        OP_DATA                                                  <true>
   38     7      > RETURN                                                   null

End of function initialize

Function buzz:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/7J10A
function name:  buzz
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'initialized'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->5
          3    >   INIT_METHOD_CALL                                         'initialize'
          4        DO_FCALL                                      0          
   44     5    >   FETCH_OBJ_R                                      ~3      'instance'
          6        INIT_METHOD_CALL                                         ~3, 'buzz'
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
   45     9*     > RETURN                                                   null

End of function buzz

End of class BuzzerProxy.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.67 ms | 1404 KiB | 17 Q