3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { protected static $instance; final public static function getInstance() { if (!isset(static::$instance)) { static::$instance = new static; } return static::$instance; } } class a1{ use Singleton; } class a2{ use Singleton; } $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/Vds9f
function name:  (null)
number of ops:  19
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_CLASS                                            'a1'
   19     1        DECLARE_CLASS                                            'a2'
   23     2        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   24     5        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !1, $4
   25     8        INIT_STATIC_METHOD_CALL                                  'a1', 'getInstance'
          9        DO_FCALL                                      0  $6      
         10        ASSIGN                                                   !0, $6
   26    11        INIT_STATIC_METHOD_CALL                                  'a2', 'getInstance'
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !1, $8
   27    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class Singleton:
Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/Vds9f
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ISSET_ISEMPTY_STATIC_PROP                        ~0      'instance'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
    8     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   11     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   12     9*     > RETURN                                                   null

End of function getinstance

End of class Singleton.

Class a1: [no user functions]
Class a2: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.26 ms | 1396 KiB | 15 Q