3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Counter { public function inc() { static $c = 0; $c = $c + 1; echo "$c\n"; return $this; } } class C1 { use Counter; } class C2 { use Counter; } $o = new C1(); $o->inc(); // echo 1 $p = new C2(); $p->inc(); // echo 1 ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtmFB
function name:  (null)
number of ops:  13
compiled vars:  !0 = $o, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_CLASS                                            'c1'
   15     1        DECLARE_CLASS                                            'c2'
   19     2        NEW                                              $2      'C1'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
          5        INIT_METHOD_CALL                                         !0, 'inc'
          6        DO_FCALL                                      0          
   20     7        NEW                                              $6      'C2'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $6
         10        INIT_METHOD_CALL                                         !1, 'inc'
         11        DO_FCALL                                      0          
   21    12      > RETURN                                                   1

Class Counter:
Function inc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtmFB
function name:  inc
number of ops:  9
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   BIND_STATIC                                              !0
    5     1        ADD                                              ~1      !0, 1
          2        ASSIGN                                                   !0, ~1
    6     3        NOP                                                      
          4        FAST_CONCAT                                      ~3      !0, '%0A'
          5        ECHO                                                     ~3
    7     6        FETCH_THIS                                       ~4      
          7      > RETURN                                                   ~4
    8     8*     > RETURN                                                   null

End of function inc

End of class Counter.

Class C1: [no user functions]
Class C2: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.38 ms | 1398 KiB | 13 Q