3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomethingBuilder { protected $value; protected $listeners = []; protected function dispatchEvent($evt){ foreach($this->listeners as $listener) $listener($evt); } function addEventListener($listener){ $this->listeners[] = $listener; } function getValue(){ return $this->value; } function setValue($value){ $this->dispatchEvent('beforechange'); $this->value = $value; } function freeze(){ return new SomethingFinalBuilderWrapper($this); } } class SomethingFinalBuilderWrapper { protected $builder; function __construct(SomethingBuilder $builder){ $this->builder = $builder; $this->builder->addEventListener(function($evt){ if($evt !== 'beforechange') return; // if(refcount($builder) > 1) $this->builder = clone $this->builder; echo "clone happened\n"; }); } function getValue(){ return $this->builder->getValue(); } } $x = new SomethingBuilder(); $x->setValue(10); echo $x->getValue() . "\n"; $y = $x->freeze(); echo $y->getValue() . "\n"; $x->setValue(20); echo $y->getValue() . "\n"; echo $x->getValue() . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  (null)
number of ops:  29
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   NEW                                              $2      'SomethingBuilder'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   48     3        INIT_METHOD_CALL                                         !0, 'setValue'
          4        SEND_VAL_EX                                              10
          5        DO_FCALL                                      0          
   49     6        INIT_METHOD_CALL                                         !0, 'getValue'
          7        DO_FCALL                                      0  $6      
          8        CONCAT                                           ~7      $6, '%0A'
          9        ECHO                                                     ~7
   51    10        INIT_METHOD_CALL                                         !0, 'freeze'
         11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !1, $8
   52    13        INIT_METHOD_CALL                                         !1, 'getValue'
         14        DO_FCALL                                      0  $10     
         15        CONCAT                                           ~11     $10, '%0A'
         16        ECHO                                                     ~11
   54    17        INIT_METHOD_CALL                                         !0, 'setValue'
         18        SEND_VAL_EX                                              20
         19        DO_FCALL                                      0          
   56    20        INIT_METHOD_CALL                                         !1, 'getValue'
         21        DO_FCALL                                      0  $13     
         22        CONCAT                                           ~14     $13, '%0A'
         23        ECHO                                                     ~14
   57    24        INIT_METHOD_CALL                                         !0, 'getValue'
         25        DO_FCALL                                      0  $15     
         26        CONCAT                                           ~16     $15, '%0A'
         27        ECHO                                                     ~16
         28      > RETURN                                                   1

Class SomethingBuilder:
Function dispatchevent:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/9A4MB
function name:  dispatchEvent
number of ops:  10
compiled vars:  !0 = $evt, !1 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_OBJ_R                                      ~2      'listeners'
          2      > FE_RESET_R                                       $3      ~2, ->8
          3    > > FE_FETCH_R                                               $3, !1, ->8
   11     4    >   INIT_DYNAMIC_CALL                                        !1
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   10     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   12     9      > RETURN                                                   null

End of function dispatchevent

Function addeventlistener:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  addEventListener
number of ops:  5
compiled vars:  !0 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        FETCH_OBJ_W                                      $1      'listeners'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   15     4      > RETURN                                                   null

End of function addeventlistener

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

End of function getvalue

Function setvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  setValue
number of ops:  7
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_METHOD_CALL                                         'dispatchEvent'
          2        SEND_VAL_EX                                              'beforechange'
          3        DO_FCALL                                      0          
   21     4        ASSIGN_OBJ                                               'value'
          5        OP_DATA                                                  !0
   22     6      > RETURN                                                   null

End of function setvalue

Function freeze:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  freeze
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $0      'SomethingFinalBuilderWrapper'
          1        FETCH_THIS                                       $1      
          2        SEND_VAR_EX                                              $1
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $0
   25     5*     > RETURN                                                   null

End of function freeze

End of class SomethingBuilder.

Class SomethingFinalBuilderWrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  __construct
number of ops:  9
compiled vars:  !0 = $builder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        ASSIGN_OBJ                                               'builder'
          2        OP_DATA                                                  !0
   34     3        FETCH_OBJ_R                                      ~2      'builder'
          4        INIT_METHOD_CALL                                         ~2, 'addEventListener'
          5        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   39     6        SEND_VAL_EX                                              ~3
   34     7        DO_FCALL                                      0          
   40     8      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $evt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        IS_NOT_IDENTICAL                                         !0, 'beforechange'
          2      > JMPZ                                                     ~1, ->4
          3    > > RETURN                                                   null
   37     4    >   FETCH_THIS                                       $2      
          5        FETCH_THIS                                       $4      
          6        FETCH_OBJ_R                                      ~5      $4, 'builder'
          7        CLONE                                            ~6      ~5
          8        ASSIGN_OBJ                                               $2, 'builder'
          9        OP_DATA                                                  ~6
   38    10        ECHO                                                     'clone+happened%0A'
   39    11      > RETURN                                                   null

End of Dynamic Function 0

End of function __construct

Function getvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9A4MB
function name:  getValue
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'builder'
          1        INIT_METHOD_CALL                                         ~0, 'getValue'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   44     4*     > RETURN                                                   null

End of function getvalue

End of class SomethingFinalBuilderWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138 ms | 1004 KiB | 13 Q