3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Session { const SESSION_STARTED = TRUE; const SESSION_NOT_STARTED = FALSE; // El estado de la sesión private $sessionState = self::SESSION_NOT_STARTED; // La única instancia de la clase private static $instance; private function __construct() {} /** * Devuelve la instancia de "sesión". * La sesión se inicializa automáticamente si no existía. * * @return Objeto **/ public static function getInstance() { if ( !isset(self::$instance)) { self::$instance = new self; } self::$instance->startSession(); return self::$instance; } /** * Inicia la sesión. * * @ Return bool TRUE si la sesión se ha inicializado, de lo contrario False. **/ public function startSession() { if ( $this->sessionState == self::SESSION_NOT_STARTED ) { $this->sessionState = session_start(); } return $this->sessionState; } /** * Carga datos de la sesión. * * @return Void **/ public function __set( $name , $value ) { $_SESSION[$name] = $value; } /** * Obtiene datos de sesión. * **/ public function __get( $name ) { if ( isset($_SESSION[$name])) { return $_SESSION[$name]; } } public function __isset( $name ) { return isset($_SESSION[$name]); } public function __unset( $name ) { unset( $_SESSION[$name] ); } /** * Destruye la sesión actual. * * @ Return bool TRUE si la sesión ha sido eliminada, de lo contrario False. **/ public function destroy() { if ( $this->sessionState == self::SESSION_STARTED ) { $this->sessionState = !session_destroy(); unset( $_SESSION ); return !$this->sessionState; } return FALSE; } } // Obtenemos la instancia de sesion $data = Session::getInstance(); // Carga datos en la sesión $data->nickname = 'Someone'; $data->age = 18; // Visualización de datos printf( '<p>My name is %s and I\'m %d years old.</p>' , $data->nickname , $data->age ); /* Se mostrará: Array ( [nickname] => Someone [age] => 18 ) */ printf( '<pre>%s</pre>' , print_r( $_SESSION , TRUE )); // TRUE var_dump( isset( $data->nickname )); // Destruimos la sesión $data->destroy(); // FALSE var_dump( isset( $data->nickname )); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  (null)
number of ops:  34
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   INIT_STATIC_METHOD_CALL                                  'Session', 'getInstance'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
  116     3        ASSIGN_OBJ                                               !0, 'nickname'
          4        OP_DATA                                                  'Someone'
  117     5        ASSIGN_OBJ                                               !0, 'age'
          6        OP_DATA                                                  18
  120     7        INIT_FCALL                                               'printf'
          8        SEND_VAL                                                 '%3Cp%3EMy+name+is+%25s+and+I%27m+%25d+years+old.%3C%2Fp%3E'
          9        FETCH_OBJ_R                                      ~5      !0, 'nickname'
         10        SEND_VAL                                                 ~5
         11        FETCH_OBJ_R                                      ~6      !0, 'age'
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                                 
  132    14        INIT_FCALL                                               'printf'
         15        SEND_VAL                                                 '%3Cpre%3E%25s%3C%2Fpre%3E'
         16        INIT_FCALL                                               'print_r'
         17        FETCH_R                      global              ~8      '_SESSION'
         18        SEND_VAL                                                 ~8
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $9      
         21        SEND_VAR                                                 $9
         22        DO_ICALL                                                 
  135    23        INIT_FCALL                                               'var_dump'
         24        ISSET_ISEMPTY_PROP_OBJ                           ~11     !0, 'nickname'
         25        SEND_VAL                                                 ~11
         26        DO_ICALL                                                 
  138    27        INIT_METHOD_CALL                                         !0, 'destroy'
         28        DO_FCALL                                      0          
  141    29        INIT_FCALL                                               'var_dump'
         30        ISSET_ISEMPTY_PROP_OBJ                           ~14     !0, 'nickname'
         31        SEND_VAL                                                 ~14
         32        DO_ICALL                                                 
  143    33      > RETURN                                                   1

Class Session:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     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/9sDcU
function name:  getInstance
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ISSET_ISEMPTY_STATIC_PROP                        ~0      'instance'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
   28     3    >   NEW                          self                $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   31     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8        INIT_METHOD_CALL                                         ~5, 'startSession'
          9        DO_FCALL                                      0          
   33    10        FETCH_STATIC_PROP_R          unknown             ~7      'instance'
         11      > RETURN                                                   ~7
   34    12*     > RETURN                                                   null

End of function getinstance

Function startsession:
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/9sDcU
function name:  startSession
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   FETCH_OBJ_R                                      ~0      'sessionState'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
   47     3    >   INIT_FCALL                                               'session_start'
          4        DO_ICALL                                         $3      
          5        ASSIGN_OBJ                                               'sessionState'
          6        OP_DATA                                                  $3
   50     7    >   FETCH_OBJ_R                                      ~4      'sessionState'
          8      > RETURN                                                   ~4
   51     9*     > RETURN                                                   null

End of function startsession

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  __set
number of ops:  6
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   62     2        FETCH_W                      global              $2      '_SESSION'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   63     5      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  __get
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
   73     1        FETCH_IS                                         ~1      '_SESSION'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   75     4    >   FETCH_R                      global              ~3      '_SESSION'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   77     7    > > RETURN                                                   null

End of function __get

Function __isset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  __isset
number of ops:  5
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
   82     1        FETCH_IS                                         ~1      '_SESSION'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   83     4*     > RETURN                                                   null

End of function __isset

Function __unset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  __unset
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
   88     1        FETCH_UNSET                                      $1      '_SESSION'
          2        UNSET_DIM                                                $1, !0
   89     3      > RETURN                                                   null

End of function __unset

Function destroy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sDcU
function name:  destroy
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  100     0  E >   FETCH_OBJ_R                                      ~0      'sessionState'
          1        BOOL                                             ~1      ~0
          2      > JMPZ                                                     ~1, ->12
  102     3    >   INIT_FCALL                                               'session_destroy'
          4        DO_ICALL                                         $3      
          5        BOOL_NOT                                         ~4      $3
          6        ASSIGN_OBJ                                               'sessionState'
          7        OP_DATA                                                  ~4
  103     8        UNSET_VAR                                                '_SESSION'
  105     9        FETCH_OBJ_R                                      ~5      'sessionState'
         10        BOOL_NOT                                         ~6      ~5
         11      > RETURN                                                   ~6
  108    12    > > RETURN                                                   <false>
  109    13*     > RETURN                                                   null

End of function destroy

End of class Session.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.83 ms | 1404 KiB | 23 Q