3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { public static function getInstance(){ static $counter = 0; static $instance = null; if (!isset($instance)) { $instance = new static(); } $counter++; echo "$counter\n"; return $instance; } } abstract class Abudabia { use Singleton; } class a1 extends Abudabia { public function set() { return 'allah ahbar'; } } class a2 extends Abudabia { public function get() { return 'algazira'; } } $a = a1::getInstance(); $b = a2::getInstance(); $a = a1::getInstance(); $b = a2::getInstance(); $a = a1::getInstance(); $b = a2::getInstance(); var_dump($a,$b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JYXfU
function name:  (null)
number of ops:  26
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_CLASS                                            'abudabia'
   20     1        DECLARE_CLASS                                            'a1', 'abudabia'
   28     2        DECLARE_CLASS                                            'a2', 'abudabia'
   36     3        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
   37     6        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   38     9        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
         10        DO_FCALL                                      0  $6      
         11        ASSIGN                                                   !0, $6
   39    12        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !1, $8
   40    15        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !0, $10
   41    18        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
         19        DO_FCALL                                      0  $12     
         20        ASSIGN                                                   !1, $12
   42    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Class Singleton:
Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/JYXfU
function name:  getInstance
number of ops:  14
compiled vars:  !0 = $counter, !1 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   BIND_STATIC                                              !0
    6     1        BIND_STATIC                                              !1
    7     2        ISSET_ISEMPTY_CV                                 ~2      !1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->8
    8     5    >   NEW                          static              $4      
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $4
   10     8    >   PRE_INC                                                  !0
   11     9        NOP                                                      
         10        FAST_CONCAT                                      ~8      !0, '%0A'
         11        ECHO                                                     ~8
   12    12      > RETURN                                                   !1
   13    13*     > RETURN                                                   null

End of function getinstance

End of class Singleton.

Class Abudabia: [no user functions]
Class a1:
Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JYXfU
function name:  set
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E > > RETURN                                                   'allah+ahbar'
   25     1*     > RETURN                                                   null

End of function set

End of class a1.

Class a2:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JYXfU
function name:  get
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E > > RETURN                                                   'algazira'
   33     1*     > RETURN                                                   null

End of function get

End of class a2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.4 ms | 1400 KiB | 15 Q