3v4l.org

run code in 300+ PHP versions simultaneously
<?php // from http://stackoverflow.com/a/3764809/4251625 function refcount($var) { ob_start(); debug_zval_dump($var); $dump = ob_get_clean(); $matches = array(); preg_match('/refcount\(([0-9]+)/', $dump, $matches); $count = $matches[1]; //3 references are added, including when calling debug_zval_dump() return $count - 3; } 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; echo refcount($this->builder); // if(refcount($this->builder) > 1) $this->builder = clone $this->builder; echo "clone happened\n"; }); } function getValue(){ return $this->builder->getValue(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TTT60
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E > > RETURN                                                   1

Function refcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TTT60
function name:  refcount
number of ops:  20
compiled vars:  !0 = $var, !1 = $dump, !2 = $matches, !3 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'ob_start'
          2        DO_ICALL                                                 
    6     3        INIT_FCALL                                               'debug_zval_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
    7     6        INIT_FCALL                                               'ob_get_clean'
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !1, $6
    9     9        ASSIGN                                                   !2, <array>
   10    10        INIT_FCALL                                               'preg_match'
         11        SEND_VAL                                                 '%2Frefcount%5C%28%28%5B0-9%5D%2B%29%2F'
         12        SEND_VAR                                                 !1
         13        SEND_REF                                                 !2
         14        DO_ICALL                                                 
   12    15        FETCH_DIM_R                                      ~10     !2, 1
         16        ASSIGN                                                   !3, ~10
   15    17        SUB                                              ~12     !3, 3
         18      > RETURN                                                   ~12
   16    19*     > RETURN                                                   null

End of function refcount

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/TTT60
function name:  dispatchEvent
number of ops:  10
compiled vars:  !0 = $evt, !1 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~2      'listeners'
          2      > FE_RESET_R                                       $3      ~2, ->8
          3    > > FE_FETCH_R                                               $3, !1, ->8
   26     4    >   INIT_DYNAMIC_CALL                                        !1
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   25     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   27     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/TTT60
function name:  addEventListener
number of ops:  5
compiled vars:  !0 = $listener
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        FETCH_OBJ_W                                      $1      'listeners'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   30     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/TTT60
function name:  getValue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
   33     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/TTT60
function name:  setValue
number of ops:  7
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_METHOD_CALL                                         'dispatchEvent'
          2        SEND_VAL_EX                                              'beforechange'
          3        DO_FCALL                                      0          
   36     4        ASSIGN_OBJ                                               'value'
          5        OP_DATA                                                  !0
   37     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/TTT60
function name:  freeze
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   NEW                                              $0      'SomethingFinalBuilderWrapper'
          1        FETCH_THIS                                       $1      
          2        SEND_VAR_EX                                              $1
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $0
   40     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/TTT60
function name:  __construct
number of ops:  9
compiled vars:  !0 = $builder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        ASSIGN_OBJ                                               'builder'
          2        OP_DATA                                                  !0
   49     3        FETCH_OBJ_R                                      ~2      'builder'
          4        INIT_METHOD_CALL                                         ~2, 'addEventListener'
          5        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   57     6        SEND_VAL_EX                                              ~3
   49     7        DO_FCALL                                      0          
   58     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/TTT60
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $evt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        IS_NOT_IDENTICAL                                         !0, 'beforechange'
          2      > JMPZ                                                     ~1, ->4
          3    > > RETURN                                                   null
   52     4    >   INIT_FCALL                                               'refcount'
          5        FETCH_THIS                                       $2      
          6        FETCH_OBJ_R                                      ~3      $2, 'builder'
          7        SEND_VAL                                                 ~3
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
   55    10        FETCH_THIS                                       $5      
         11        FETCH_THIS                                       $7      
         12        FETCH_OBJ_R                                      ~8      $7, 'builder'
         13        CLONE                                            ~9      ~8
         14        ASSIGN_OBJ                                               $5, 'builder'
         15        OP_DATA                                                  ~9
   56    16        ECHO                                                     'clone+happened%0A'
   57    17      > 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/TTT60
function name:  getValue
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'builder'
          1        INIT_METHOD_CALL                                         ~0, 'getValue'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   62     4*     > RETURN                                                   null

End of function getvalue

End of class SomethingFinalBuilderWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.41 ms | 1012 KiB | 18 Q