3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait Singleton { # Holds Parent Instance private static $_instance; # Holds Current zval private $_arg; # No Direct Need For This Other Than Stopping Call To new Class private function __construct() {} # Singleton Design public static function getInstance() { return self::$_instance ?? (self::$_instance = new self()); } # Store a reference of the variable to share the zval # Needed to re-pass the variable by reference to share the zval to _arg public function bindArg(&$arg) { $this->_arg =& $arg; } # Output the value of the stored reference if exists public function helloWorld() { echo $this->_arg ?? 'Did not exist.'; } } final class Test { use \Singleton { helloWorld as public peekabo; } } Test::getInstance()->bindArg($row); foreach(['Hello', ',', ' World'] as $row) Test::getInstance()->peekabo();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/EWJs2
function name:  (null)
number of ops:  15
compiled vars:  !0 = $row
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   DECLARE_CLASS                                                'test'
   29     1        INIT_STATIC_METHOD_CALL                                      'Test', 'getInstance'
          2        DO_FCALL                                          0  $1      
          3        INIT_METHOD_CALL                                             $1, 'bindArg'
          4        SEND_VAR_EX                                                  !0
          5        DO_FCALL                                          0          
   31     6      > FE_RESET_R                                           $3      <array>, ->13
          7    > > FE_FETCH_R                                                   $3, !0, ->13
   32     8    >   INIT_STATIC_METHOD_CALL                                      'Test', 'getInstance'
          9        DO_FCALL                                          0  $4      
         10        INIT_METHOD_CALL                                             $4, 'peekabo'
         11        DO_FCALL                                          0          
   31    12      > JMP                                                          ->7
         13    >   FE_FREE                                                      $3
   32    14      > RETURN                                                       1

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

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EWJs2
function name:  getInstance
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   FETCH_STATIC_PROP_IS                                 ~0      '_instance'
          1        COALESCE                                             ~1      ~0
          2        NEW                              self                $3      
          3        DO_FCALL                                          0          
          4        ASSIGN_STATIC_PROP                                   ~2      '_instance'
          5        OP_DATA                                                      $3
          6        QM_ASSIGN                                            ~1      ~2
          7      > RETURN                                                       ~1
   15     8*     > RETURN                                                       null

End of function getinstance

Function bindarg:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EWJs2
function name:  bindArg
number of ops:  4
compiled vars:  !0 = $arg
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ_REF                                               '_arg'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function bindarg

Function helloworld:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EWJs2
function name:  helloWorld
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   FETCH_OBJ_IS                                         ~0      '_arg'
          1        COALESCE                                             ~1      ~0
          2        QM_ASSIGN                                            ~1      'Did+not+exist.'
          3        ECHO                                                         ~1
          4      > RETURN                                                       null

End of function helloworld

End of class Singleton.

Class Test: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.72 ms | 2224 KiB | 13 Q