3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Authenticator { protected $isloggedin; protected $session; public function __construct(Session $session) { $this->session = $session; // if ( ! empty($session->get('isloggedin')) && $session->get('isloggedin') == true) { $isl = $session->get('isloggedin'); if ( ! empty($isl) && $isl == true) { $this->isloggedin = true; } $uid = $session->get('userid'); if ( ! empty($uid) && (int) $uid == $uid ) { $this->userid = (int) $uid; } } public function authenticate($username, $password) { if ($this->isloggedin) return true; if ( empty($username)) return false; if ( empty($password)) return false; // ... return false; } public function logout() { $this->isloggedin = false; $this->userid = 0; $this->session->del('isloggedin'); $this->session->del('userid'); } public function isloggedin() { return $this->isloggedin; } } interface Session { public function set($key, $val=true); public function del($key, $val=false); public function get($key); } class BasicSession implements Session { protected $session = array(); public function __construct() { if ( ! session_start() ) { throw new Exception('Could not initiate web session'); } $this->session = $_SESSION; } public function set($key, $val=true) { $this->session[$key] = $val; } public function del($key, $val=false) { if (isset($this->session[$key])) { $this->session[$key] = $val; unset($this->session[$key]); } } public function get($key) { if (isset($this->session[$key])) { return $this->session[$key]; } return false; } } try { $sess = new BasicSession(); $auth = new Authenticator($sess); } catch (Exception $e) { die('System go KA-BOOM! ' . $e->getMessage()); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 9
Branch analysis from position: 9
2 jumps found. (Code = 107) Position 1 = 10, Position 2 = -2
Branch analysis from position: 10
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/EOUhh
function name:  (null)
number of ops:  15
compiled vars:  !0 = $sess, !1 = $auth, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   DECLARE_CLASS                                            'basicsession'
   88     1        NEW                                              $3      'BasicSession'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   89     4        NEW                                              $6      'Authenticator'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
          8      > JMP                                                      ->14
   90     9  E > > CATCH                                       last         'Exception'
   91    10    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         11        DO_FCALL                                      0  $9      
         12        CONCAT                                           ~10     'System+go+KA-BOOM%21+', $9
         13      > EXIT                                                     ~10
   92    14    > > RETURN                                                   1

Class Authenticator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 25
Branch analysis from position: 15
Branch analysis from position: 12
filename:       /in/EOUhh
function name:  __construct
number of ops:  30
compiled vars:  !0 = $session, !1 = $isl, !2 = $uid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               'session'
          2        OP_DATA                                                  !0
   11     3        INIT_METHOD_CALL                                         !0, 'get'
          4        SEND_VAL_EX                                              'isloggedin'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   12     7        ISSET_ISEMPTY_CV                                 ~6      !1
          8        BOOL_NOT                                         ~7      ~6
          9      > JMPZ_EX                                          ~7      ~7, ->12
         10    >   BOOL                                             ~8      !1
         11        BOOL                                             ~7      ~8
         12    > > JMPZ                                                     ~7, ->15
   13    13    >   ASSIGN_OBJ                                               'isloggedin'
         14        OP_DATA                                                  <true>
   16    15    >   INIT_METHOD_CALL                                         !0, 'get'
         16        SEND_VAL_EX                                              'userid'
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !2, $10
   17    19        ISSET_ISEMPTY_CV                                 ~12     !2
         20        BOOL_NOT                                         ~13     ~12
         21      > JMPZ_EX                                          ~13     ~13, ->25
         22    >   CAST                                          4  ~14     !2
         23        IS_EQUAL                                         ~15     !2, ~14
         24        BOOL                                             ~13     ~15
         25    > > JMPZ                                                     ~13, ->29
   18    26    >   CAST                                          4  ~17     !2
         27        ASSIGN_OBJ                                               'userid'
         28        OP_DATA                                                  ~17
   20    29    > > RETURN                                                   null

End of function __construct

Function authenticate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  authenticate
number of ops:  13
compiled vars:  !0 = $username, !1 = $password
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        FETCH_OBJ_R                                      ~2      'isloggedin'
          3      > JMPZ                                                     ~2, ->5
   24     4    > > RETURN                                                   <true>
   26     5    >   ISSET_ISEMPTY_CV                                         !0
          6      > JMPZ                                                     ~3, ->8
   27     7    > > RETURN                                                   <false>
   29     8    >   ISSET_ISEMPTY_CV                                         !1
          9      > JMPZ                                                     ~4, ->11
   30    10    > > RETURN                                                   <false>
   34    11    > > RETURN                                                   <false>
   35    12*     > RETURN                                                   null

End of function authenticate

Function logout:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  logout
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN_OBJ                                               'isloggedin'
          1        OP_DATA                                                  <false>
   39     2        ASSIGN_OBJ                                               'userid'
          3        OP_DATA                                                  0
   41     4        FETCH_OBJ_R                                      ~2      'session'
          5        INIT_METHOD_CALL                                         ~2, 'del'
          6        SEND_VAL_EX                                              'isloggedin'
          7        DO_FCALL                                      0          
   42     8        FETCH_OBJ_R                                      ~4      'session'
          9        INIT_METHOD_CALL                                         ~4, 'del'
         10        SEND_VAL_EX                                              'userid'
         11        DO_FCALL                                      0          
   43    12      > RETURN                                                   null

End of function logout

Function isloggedin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  isloggedin
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   FETCH_OBJ_R                                      ~0      'isloggedin'
          1      > RETURN                                                   ~0
   47     2*     > RETURN                                                   null

End of function isloggedin

End of class Authenticator.

Class Session:
Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  set
number of ops:  3
compiled vars:  !0 = $key, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
          2      > RETURN                                                   null

End of function set

Function del:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  del
number of ops:  3
compiled vars:  !0 = $key, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
          2      > RETURN                                                   null

End of function del

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  get
number of ops:  2
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function get

End of class Session.

Class BasicSession:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  __construct
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'session_start'
          1        DO_ICALL                                         $0      
          2        BOOL_NOT                                         ~1      $0
          3      > JMPZ                                                     ~1, ->8
   62     4    >   NEW                                              $2      'Exception'
          5        SEND_VAL_EX                                              'Could+not+initiate+web+session'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $2
   64     8    >   FETCH_R                      global              ~5      '_SESSION'
          9        ASSIGN_OBJ                                               'session'
         10        OP_DATA                                                  ~5
   65    11      > RETURN                                                   null

End of function __construct

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOUhh
function name:  set
number of ops:  6
compiled vars:  !0 = $key, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   68     2        FETCH_OBJ_W                                      $2      'session'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   69     5      > RETURN                                                   null

End of function set

Function del:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/EOUhh
function name:  del
number of ops:  11
compiled vars:  !0 = $key, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   72     2        FETCH_OBJ_IS                                     ~2      'session'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->10
   73     5    >   FETCH_OBJ_W                                      $4      'session'
          6        ASSIGN_DIM                                               $4, !0
          7        OP_DATA                                                  !1
   74     8        FETCH_OBJ_UNSET                                  $6      'session'
          9        UNSET_DIM                                                $6, !0
   76    10    > > RETURN                                                   null

End of function del

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/EOUhh
function name:  get
number of ops:  9
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   79     1        FETCH_OBJ_IS                                     ~1      'session'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   80     4    >   FETCH_OBJ_R                                      ~3      'session'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   82     7    > > RETURN                                                   <false>
   83     8*     > RETURN                                                   null

End of function get

End of class BasicSession.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.47 ms | 1404 KiB | 15 Q