3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Social network site where you can see a list of users and "follow" them. */ // setup the `Db` object: //require_once 'lib/db.php'; // setup the `Session` object: //require_once 'lib/session.php'; if (!Session::isLoggedIn()) { throw new Exception('You must be logged in to view this page'); } // display a user as html function displayUser ($user, $tag='div') { $full_name = $user->first_name . ' ' . $user->last_name; // get user's avatar from 3rd-party avatar service, based on which environment we're running in if (strpos($_SERVER['SERVER_NAME'], 'localhost') !== false) { $avatar_data = json_decode(file_get_contents('http://dev.avatars.com/user/' . $user->id)); } else { $avatar_data = json_decode(file_get_contents('http://www.avatars.com/user/' . $user->id)); } ?> <<?= $tag ?> class="user"> <a href="/users/<?= $user->id ?>"> <img src="<?= $avatar_data->url ?>"> <?= $full_name ?> </a> <a href="?follow=<?= $user->id ?>">Follow</a> </<?= $tag ?>> <?php } // check that a user ID is valid (must be a number) function validateUserId ($id) { if (!is_numeric($id)) { // log invalid user IDs to help us track down bugs. error_log("Invalid user id: {$id}"); return false; } return true; } // load the user's custom theme config $theme_filename = dirname(__FILE__) . 'themes/' . Session::getLoggedInUser()->theme_id . '.php'; if (file_exists($theme_filename)) { require $theme_filename; } // show all users if (isset($_GET['show-all'])) { echo '<ul>'; foreach (Db::getUsers() as $user) { displayUser($user, 'li'); } echo '</ul>'; } // show a single user else if (isset($_GET['id'])) { $id = $_GET['id']; if (!validateUserId($id)) throw new Exception('Please select a valid user ID'); $user = Db::getUserById($id); if (!$user) throw new Exception('Sorry, user not found'); displayUser($user); } // follow a user else if (isset($_GET['follow'])) { $id = $_GET['follow']; if (!validateUserId($id)) throw new Exception('Please select a valid user ID'); $user_to_follow = Db::getUserById($id); if (!$user_to_follow) throw new Exception('Sorry, user not found'); $current_user = Session::getLoggedInUser(); try { $current_user->follow($user_to_follow); } catch (Exception $e) { throw new Exception('Unable to follow at this time'); } // inform the user that they have a new follower. mail( $user_to_follow->email, 'You have a new follower!', "{$current_user->username} is now following you.", 'From: notifications@awesome-social-network.com' ); // also update the activity feed, so users can see what others are doing on the site. Db::updateActivityFeed(array( 'action' => 'follow', 'from' => $current_user->id, 'to' => $user_to_follow->id, 'timestamp' => time(), )); echo 'Followed! <a href="/">Return to home</a>'; } ?>
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
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 68
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 64
Branch analysis from position: 60
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 127
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 83
Branch analysis from position: 79
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 93
Branch analysis from position: 89
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 127
Branch analysis from position: 23
Found catch point at position: 100
Branch analysis from position: 100
2 jumps found. (Code = 107) Position 1 = 101, Position 2 = -2
Branch analysis from position: 101
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/ihbdG
function name:  (null)
number of ops:  128
compiled vars:  !0 = $theme_filename, !1 = $user, !2 = $id, !3 = $user_to_follow, !4 = $current_user, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_STATIC_METHOD_CALL                                  'Session', 'isLoggedIn'
          1        DO_FCALL                                      0  $6      
          2        BOOL_NOT                                         ~7      $6
          3      > JMPZ                                                     ~7, ->8
   14     4    >   NEW                                              $8      'Exception'
          5        SEND_VAL_EX                                              'You+must+be+logged+in+to+view+this+page'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $8
   52     8    >   INIT_FCALL                                               'dirname'
          9        SEND_VAL                                                 '%2Fin%2FihbdG'
         10        DO_ICALL                                         $10     
         11        CONCAT                                           ~11     $10, 'themes%2F'
         12        INIT_STATIC_METHOD_CALL                                  'Session', 'getLoggedInUser'
         13        DO_FCALL                                      0  $12     
         14        FETCH_OBJ_R                                      ~13     $12, 'theme_id'
         15        CONCAT                                           ~14     ~11, ~13
         16        CONCAT                                           ~15     ~14, '.php'
         17        ASSIGN                                                   !0, ~15
   53    18        INIT_FCALL                                               'file_exists'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $17     
         21      > JMPZ                                                     $17, ->23
   54    22    >   INCLUDE_OR_EVAL                                          !0, REQUIRE
   58    23    >   FETCH_IS                                         ~19     '_GET'
         24        ISSET_ISEMPTY_DIM_OBJ                         0          ~19, 'show-all'
         25      > JMPZ                                                     ~20, ->39
   59    26    >   ECHO                                                     '%3Cul%3E'
   60    27        INIT_STATIC_METHOD_CALL                                  'Db', 'getUsers'
         28        DO_FCALL                                      0  $21     
         29      > FE_RESET_R                                       $22     $21, ->36
         30    > > FE_FETCH_R                                               $22, !1, ->36
   61    31    >   INIT_FCALL                                               'displayuser'
         32        SEND_VAR                                                 !1
         33        SEND_VAL                                                 'li'
         34        DO_FCALL                                      0          
   60    35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $22
   63    37        ECHO                                                     '%3C%2Ful%3E'
         38      > JMP                                                      ->127
   66    39    >   FETCH_IS                                         ~24     '_GET'
         40        ISSET_ISEMPTY_DIM_OBJ                         0          ~24, 'id'
         41      > JMPZ                                                     ~25, ->68
   67    42    >   FETCH_R                      global              ~26     '_GET'
         43        FETCH_DIM_R                                      ~27     ~26, 'id'
         44        ASSIGN                                                   !2, ~27
   68    45        INIT_FCALL                                               'validateuserid'
         46        SEND_VAR                                                 !2
         47        DO_FCALL                                      0  $29     
         48        BOOL_NOT                                         ~30     $29
         49      > JMPZ                                                     ~30, ->54
         50    >   NEW                                              $31     'Exception'
         51        SEND_VAL_EX                                              'Please+select+a+valid+user+ID'
         52        DO_FCALL                                      0          
         53      > THROW                                         0          $31
   69    54    >   INIT_STATIC_METHOD_CALL                                  'Db', 'getUserById'
         55        SEND_VAR_EX                                              !2
         56        DO_FCALL                                      0  $33     
         57        ASSIGN                                                   !1, $33
   70    58        BOOL_NOT                                         ~35     !1
         59      > JMPZ                                                     ~35, ->64
         60    >   NEW                                              $36     'Exception'
         61        SEND_VAL_EX                                              'Sorry%2C+user+not+found'
         62        DO_FCALL                                      0          
         63      > THROW                                         0          $36
   72    64    >   INIT_FCALL                                               'displayuser'
         65        SEND_VAR                                                 !1
         66        DO_FCALL                                      0          
         67      > JMP                                                      ->127
   75    68    >   FETCH_IS                                         ~39     '_GET'
         69        ISSET_ISEMPTY_DIM_OBJ                         0          ~39, 'follow'
         70      > JMPZ                                                     ~40, ->127
   76    71    >   FETCH_R                      global              ~41     '_GET'
         72        FETCH_DIM_R                                      ~42     ~41, 'follow'
         73        ASSIGN                                                   !2, ~42
   77    74        INIT_FCALL                                               'validateuserid'
         75        SEND_VAR                                                 !2
         76        DO_FCALL                                      0  $44     
         77        BOOL_NOT                                         ~45     $44
         78      > JMPZ                                                     ~45, ->83
         79    >   NEW                                              $46     'Exception'
         80        SEND_VAL_EX                                              'Please+select+a+valid+user+ID'
         81        DO_FCALL                                      0          
         82      > THROW                                         0          $46
   78    83    >   INIT_STATIC_METHOD_CALL                                  'Db', 'getUserById'
         84        SEND_VAR_EX                                              !2
         85        DO_FCALL                                      0  $48     
         86        ASSIGN                                                   !3, $48
   79    87        BOOL_NOT                                         ~50     !3
         88      > JMPZ                                                     ~50, ->93
         89    >   NEW                                              $51     'Exception'
         90        SEND_VAL_EX                                              'Sorry%2C+user+not+found'
         91        DO_FCALL                                      0          
         92      > THROW                                         0          $51
   81    93    >   INIT_STATIC_METHOD_CALL                                  'Session', 'getLoggedInUser'
         94        DO_FCALL                                      0  $53     
         95        ASSIGN                                                   !4, $53
   83    96        INIT_METHOD_CALL                                         !4, 'follow'
         97        SEND_VAR_EX                                              !3
         98        DO_FCALL                                      0          
         99      > JMP                                                      ->105
   84   100  E > > CATCH                                       last         'Exception'
   85   101    >   NEW                                              $56     'Exception'
        102        SEND_VAL_EX                                              'Unable+to+follow+at+this+time'
        103        DO_FCALL                                      0          
        104      > THROW                                         0          $56
   89   105    >   INIT_FCALL                                               'mail'
   90   106        FETCH_OBJ_R                                      ~58     !3, 'email'
        107        SEND_VAL                                                 ~58
   91   108        SEND_VAL                                                 'You+have+a+new+follower%21'
   92   109        FETCH_OBJ_R                                      ~59     !4, 'username'
        110        NOP                                                      
        111        FAST_CONCAT                                      ~60     ~59, '+is+now+following+you.'
        112        SEND_VAL                                                 ~60
   93   113        SEND_VAL                                                 'From%3A+notifications%40awesome-social-network.com'
        114        DO_ICALL                                                 
   97   115        INIT_STATIC_METHOD_CALL                                  'Db', 'updateActivityFeed'
   98   116        INIT_ARRAY                                       ~62     'follow', 'action'
   99   117        FETCH_OBJ_R                                      ~63     !4, 'id'
        118        ADD_ARRAY_ELEMENT                                ~62     ~63, 'from'
  100   119        FETCH_OBJ_R                                      ~64     !3, 'id'
        120        ADD_ARRAY_ELEMENT                                ~62     ~64, 'to'
  101   121        INIT_FCALL                                               'time'
        122        DO_ICALL                                         $65     
        123        ADD_ARRAY_ELEMENT                                ~62     $65, 'timestamp'
        124        SEND_VAL_EX                                              ~62
        125        DO_FCALL                                      0          
  104   126        ECHO                                                     'Followed%21+%3Ca+href%3D%22%2F%22%3EReturn+to+home%3C%2Fa%3E'
  107   127    > > RETURN                                                   1

Function displayuser:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ihbdG
function name:  displayUser
number of ops:  51
compiled vars:  !0 = $user, !1 = $tag, !2 = $full_name, !3 = $avatar_data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'div'
   19     2        FETCH_OBJ_R                                      ~4      !0, 'first_name'
          3        CONCAT                                           ~5      ~4, '+'
          4        FETCH_OBJ_R                                      ~6      !0, 'last_name'
          5        CONCAT                                           ~7      ~5, ~6
          6        ASSIGN                                                   !2, ~7
   22     7        INIT_FCALL                                               'strpos'
          8        FETCH_R                      global              ~9      '_SERVER'
          9        FETCH_DIM_R                                      ~10     ~9, 'SERVER_NAME'
         10        SEND_VAL                                                 ~10
         11        SEND_VAL                                                 'localhost'
         12        DO_ICALL                                         $11     
         13        TYPE_CHECK                                  1018          $11
         14      > JMPZ                                                     ~12, ->25
   23    15    >   INIT_FCALL                                               'json_decode'
         16        INIT_FCALL                                               'file_get_contents'
         17        FETCH_OBJ_R                                      ~13     !0, 'id'
         18        CONCAT                                           ~14     'http%3A%2F%2Fdev.avatars.com%2Fuser%2F', ~13
         19        SEND_VAL                                                 ~14
         20        DO_ICALL                                         $15     
         21        SEND_VAR                                                 $15
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !3, $16
         24      > JMP                                                      ->34
   26    25    >   INIT_FCALL                                               'json_decode'
         26        INIT_FCALL                                               'file_get_contents'
         27        FETCH_OBJ_R                                      ~18     !0, 'id'
         28        CONCAT                                           ~19     'http%3A%2F%2Fwww.avatars.com%2Fuser%2F', ~18
         29        SEND_VAL                                                 ~19
         30        DO_ICALL                                         $20     
         31        SEND_VAR                                                 $20
         32        DO_ICALL                                         $21     
         33        ASSIGN                                                   !3, $21
   30    34    >   ECHO                                                     '++++%3C'
         35        ECHO                                                     !1
         36        ECHO                                                     '+class%3D%22user%22%3E%0A%09%3Ca+href%3D%22%2Fusers%2F'
   31    37        FETCH_OBJ_R                                      ~23     !0, 'id'
         38        ECHO                                                     ~23
         39        ECHO                                                     '%22%3E%0A%09++++%3Cimg+src%3D%22'
   32    40        FETCH_OBJ_R                                      ~24     !3, 'url'
         41        ECHO                                                     ~24
         42        ECHO                                                     '%22%3E%0A%09++++'
   33    43        ECHO                                                     !2
   34    44        ECHO                                                     '%09%3C%2Fa%3E%0A%09%3Ca+href%3D%22%3Ffollow%3D'
   35    45        FETCH_OBJ_R                                      ~25     !0, 'id'
         46        ECHO                                                     ~25
         47        ECHO                                                     '%22%3EFollow%3C%2Fa%3E%0A++++%3C%2F'
   36    48        ECHO                                                     !1
         49        ECHO                                                     '%3E%0A'
   38    50      > RETURN                                                   null

End of function displayuser

Function validateuserid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ihbdG
function name:  validateUserId
number of ops:  14
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   42     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->12
   44     6    >   INIT_FCALL                                               'error_log'
          7        NOP                                                      
          8        FAST_CONCAT                                      ~3      'Invalid+user+id%3A+', !0
          9        SEND_VAL                                                 ~3
         10        DO_ICALL                                                 
   45    11      > RETURN                                                   <false>
   48    12    > > RETURN                                                   <true>
   49    13*     > RETURN                                                   null

End of function validateuserid

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.51 ms | 1423 KiB | 35 Q