3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Session { private $started = false; public function start() { if ($this->started) { return; } session_start(); $this->started = true; } } class AutostartingSessionBag implements ArrayAccess { private $session; public function __construct(Session $session) { $this->session = $session; } public function offsetExists($offset) { $this->ensureSessionStarted(); return isset($_SESSION[$offset]); } public function offsetGet($offset) { $this->ensureSessionStarted(); return $_SESSION[$offset]; } public function offsetSet($offset, $vaue) { $this->ensureSessionStarted(); $_SESSION[$offset] = $value; } public function offsetUnset($offset) { $this->ensureSessionStarted(); unset($_SESSION[$offset]); } private function ensureSessionStarted() { $this->session->start(); } } //var_dump($_SESSION); $_SESSION = new AutostartingSessionBag(new Session()); var_dump($_SESSION); $_SESSION['test'] = 'foobar'; var_dump($_SESSION);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   DECLARE_CLASS                                            'autostartingsessionbag'
   57     1        NEW                                              $1      'AutostartingSessionBag'
          2        NEW                                              $2      'Session'
          3        DO_FCALL                                      0          
          4        SEND_VAR_NO_REF_EX                                       $2
          5        DO_FCALL                                      0          
          6        FETCH_W                      global              $0      '_SESSION'
          7        ASSIGN                                                   $0, $1
   58     8        INIT_FCALL                                               'var_dump'
          9        FETCH_R                      global              ~6      '_SESSION'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                                 
   59    12        FETCH_W                      global              $8      '_SESSION'
         13        ASSIGN_DIM                                               $8, 'test'
         14        OP_DATA                                                  'foobar'
   60    15        INIT_FCALL                                               'var_dump'
         16        FETCH_R                      global              ~10     '_SESSION'
         17        SEND_VAL                                                 ~10
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Class Session:
Function start:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 3
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  start
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'started'
          1      > JMPZ                                                     ~0, ->3
   10     2    > > RETURN                                                   null
   12     3    >   INIT_FCALL                                               'session_start'
          4        DO_ICALL                                                 
   13     5        ASSIGN_OBJ                                               'started'
          6        OP_DATA                                                  <true>
   14     7      > RETURN                                                   null

End of function start

End of class Session.

Class AutostartingSessionBag:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $session
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        ASSIGN_OBJ                                               'session'
          2        OP_DATA                                                  !0
   24     3      > RETURN                                                   null

End of function __construct

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  offsetExists
number of ops:  7
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        INIT_METHOD_CALL                                         'ensureSessionStarted'
          2        DO_FCALL                                      0          
   29     3        FETCH_IS                                         ~2      '_SESSION'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !0
          5      > RETURN                                                   ~3
   30     6*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  offsetGet
number of ops:  7
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        INIT_METHOD_CALL                                         'ensureSessionStarted'
          2        DO_FCALL                                      0          
   35     3        FETCH_R                      global              ~2      '_SESSION'
          4        FETCH_DIM_R                                      ~3      ~2, !0
          5      > RETURN                                                   ~3
   36     6*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  offsetSet
number of ops:  8
compiled vars:  !0 = $offset, !1 = $vaue, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        INIT_METHOD_CALL                                         'ensureSessionStarted'
          3        DO_FCALL                                      0          
   41     4        FETCH_W                      global              $4      '_SESSION'
          5        ASSIGN_DIM                                               $4, !0
          6        OP_DATA                                                  !2
   42     7      > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  offsetUnset
number of ops:  6
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   46     1        INIT_METHOD_CALL                                         'ensureSessionStarted'
          2        DO_FCALL                                      0          
   47     3        FETCH_UNSET                                      $2      '_SESSION'
          4        UNSET_DIM                                                $2, !0
   48     5      > RETURN                                                   null

End of function offsetunset

Function ensuresessionstarted:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HTfNE
function name:  ensureSessionStarted
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'session'
          1        INIT_METHOD_CALL                                         ~0, 'start'
          2        DO_FCALL                                      0          
   53     3      > RETURN                                                   null

End of function ensuresessionstarted

End of class AutostartingSessionBag.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.26 ms | 1404 KiB | 17 Q