3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { protected static $instance = null; /** * make contrutor not public */ protected function __construct() { } /** * @return static */ public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } } class ExampleSingleton extends Singleton { public $name = 'x'; } $s = ExampleSingleton::getInstance(); echo $s->name; $s->name = 'y'; echo ExampleSingleton::getInstance()->name; $s2 = new ExampleSingleton(); echo $s2->name;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K0CkO
function name:  (null)
number of ops:  17
compiled vars:  !0 = $s, !1 = $s2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_STATIC_METHOD_CALL                                  'ExampleSingleton', 'getInstance'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   36     3        FETCH_OBJ_R                                      ~4      !0, 'name'
          4        ECHO                                                     ~4
   38     5        ASSIGN_OBJ                                               !0, 'name'
          6        OP_DATA                                                  'y'
   40     7        INIT_STATIC_METHOD_CALL                                  'ExampleSingleton', 'getInstance'
          8        DO_FCALL                                      0  $6      
          9        FETCH_OBJ_R                                      ~7      $6, 'name'
         10        ECHO                                                     ~7
   42    11        NEW                                              $8      'ExampleSingleton'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $8
   43    14        FETCH_OBJ_R                                      ~11     !1, 'name'
         15        ECHO                                                     ~11
         16      > RETURN                                                   1

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

End of function __construct

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/K0CkO
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   23     3    >   NEW                          self                $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   25     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   26     9*     > RETURN                                                   null

End of function getinstance

End of class Singleton.

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

End of function __construct

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/K0CkO
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   23     3    >   NEW                          self                $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   25     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   26     9*     > RETURN                                                   null

End of function getinstance

End of class ExampleSingleton.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.12 ms | 1390 KiB | 13 Q