3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public function run() { echo 'Hello' . PHP_EOL; } } class AppContainer { private static $app = null; public static function getInstance() { if (null === self::$app) { self::$app = self::makeInstance(); } return self::$app; } private static function makeInstance() { $app = new App(); // do all logic for adding routes etc return $app; } } // Whenever you need it $app1 = AppContainer::getInstance(); $app2 = AppContainer::getInstance(); if ($app1 === $app2) { echo 'yay, same object' . PHP_EOL; } $app1->run(); $app2->run();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/5bcr0
function name:  (null)
number of ops:  14
compiled vars:  !0 = $app1, !1 = $app2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_STATIC_METHOD_CALL                                  'AppContainer', 'getInstance'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   35     3        INIT_STATIC_METHOD_CALL                                  'AppContainer', 'getInstance'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   37     6        IS_IDENTICAL                                             !0, !1
          7      > JMPZ                                                     ~6, ->9
   38     8    >   ECHO                                                     'yay%2C+same+object%0A'
   41     9    >   INIT_METHOD_CALL                                         !0, 'run'
         10        DO_FCALL                                      0          
   42    11        INIT_METHOD_CALL                                         !1, 'run'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Class App:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5bcr0
function name:  run
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ECHO                                                     'Hello%0A'
    8     1      > RETURN                                                   null

End of function run

End of class App.

Class AppContainer:
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/5bcr0
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'app'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   18     3    >   INIT_STATIC_METHOD_CALL                                  'makeInstance'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_STATIC_PROP                                       'app'
          6        OP_DATA                                                  $3
   21     7    >   FETCH_STATIC_PROP_R          unknown             ~4      'app'
          8      > RETURN                                                   ~4
   22     9*     > RETURN                                                   null

End of function getinstance

Function makeinstance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5bcr0
function name:  makeInstance
number of ops:  5
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $1      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   29     3      > RETURN                                                   !0
   30     4*     > RETURN                                                   null

End of function makeinstance

End of class AppContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.4 ms | 1399 KiB | 13 Q