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)) { echo 'new instance has been set'; $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/Uo3J9
function name:  (null)
number of ops:  26
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   DECLARE_CLASS                                            'abudabia'
   21     1        DECLARE_CLASS                                            'a1', 'abudabia'
   29     2        DECLARE_CLASS                                            'a2', 'abudabia'
   37     3        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
   38     6        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   39     9        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
         10        DO_FCALL                                      0  $6      
         11        ASSIGN                                                   !0, $6
   40    12        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !1, $8
   41    15        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !0, $10
   42    18        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
         19        DO_FCALL                                      0  $12     
         20        ASSIGN                                                   !1, $12
   43    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 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/Uo3J9
function name:  getInstance
number of ops:  15
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, ->9
    8     5    >   ECHO                                                     'new+instance+has+been+set'
    9     6        NEW                          static              $4      
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $4
   11     9    >   PRE_INC                                                  !0
   12    10        NOP                                                      
         11        FAST_CONCAT                                      ~8      !0, '%0A'
         12        ECHO                                                     ~8
   13    13      > RETURN                                                   !1
   14    14*     > 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/Uo3J9
function name:  set
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E > > RETURN                                                   'allah+ahbar'
   26     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/Uo3J9
function name:  get
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E > > RETURN                                                   'algazira'
   34     1*     > RETURN                                                   null

End of function get

End of class a2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.45 ms | 1400 KiB | 15 Q