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 (true) { $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 = 3, Position 2 = 16
Branch analysis from position: 3
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 = 42) Position 1 = 102
Branch analysis from position: 102
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 43
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 39
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 102
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 58
Branch analysis from position: 54
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
Found catch point at position: 75
Branch analysis from position: 75
2 jumps found. (Code = 107) Position 1 = 76, Position 2 = -2
Branch analysis from position: 76
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/BhAOP
function name:  (null)
number of ops:  103
compiled vars:  !0 = $user, !1 = $id, !2 = $user_to_follow, !3 = $current_user, !4 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   FETCH_IS                                         ~5      '_GET'
          1        ISSET_ISEMPTY_DIM_OBJ                         0          ~5, 'show-all'
          2      > JMPZ                                                     ~6, ->16
   59     3    >   ECHO                                                     '%3Cul%3E'
   60     4        INIT_STATIC_METHOD_CALL                                  'Db', 'getUsers'
          5        DO_FCALL                                      0  $7      
          6      > FE_RESET_R                                       $8      $7, ->13
          7    > > FE_FETCH_R                                               $8, !0, ->13
   61     8    >   INIT_FCALL                                               'displayuser'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'li'
         11        DO_FCALL                                      0          
   60    12      > JMP                                                      ->7
         13    >   FE_FREE                                                  $8
   63    14        ECHO                                                     '%3C%2Ful%3E'
         15      > JMP                                                      ->102
   66    16    > > JMPZ                                                     <true>, ->43
   67    17    >   FETCH_R                      global              ~10     '_GET'
         18        FETCH_DIM_R                                      ~11     ~10, 'id'
         19        ASSIGN                                                   !1, ~11
   68    20        INIT_FCALL                                               'validateuserid'
         21        SEND_VAR                                                 !1
         22        DO_FCALL                                      0  $13     
         23        BOOL_NOT                                         ~14     $13
         24      > JMPZ                                                     ~14, ->29
         25    >   NEW                                              $15     'Exception'
         26        SEND_VAL_EX                                              'Please+select+a+valid+user+ID'
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $15
   69    29    >   INIT_STATIC_METHOD_CALL                                  'Db', 'getUserById'
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0  $17     
         32        ASSIGN                                                   !0, $17
   70    33        BOOL_NOT                                         ~19     !0
         34      > JMPZ                                                     ~19, ->39
         35    >   NEW                                              $20     'Exception'
         36        SEND_VAL_EX                                              'Sorry%2C+user+not+found'
         37        DO_FCALL                                      0          
         38      > THROW                                         0          $20
   72    39    >   INIT_FCALL                                               'displayuser'
         40        SEND_VAR                                                 !0
         41        DO_FCALL                                      0          
         42      > JMP                                                      ->102
   75    43    >   FETCH_IS                                         ~23     '_GET'
         44        ISSET_ISEMPTY_DIM_OBJ                         0          ~23, 'follow'
         45      > JMPZ                                                     ~24, ->102
   76    46    >   FETCH_R                      global              ~25     '_GET'
         47        FETCH_DIM_R                                      ~26     ~25, 'follow'
         48        ASSIGN                                                   !1, ~26
   77    49        INIT_FCALL                                               'validateuserid'
         50        SEND_VAR                                                 !1
         51        DO_FCALL                                      0  $28     
         52        BOOL_NOT                                         ~29     $28
         53      > JMPZ                                                     ~29, ->58
         54    >   NEW                                              $30     'Exception'
         55        SEND_VAL_EX                                              'Please+select+a+valid+user+ID'
         56        DO_FCALL                                      0          
         57      > THROW                                         0          $30
   78    58    >   INIT_STATIC_METHOD_CALL                                  'Db', 'getUserById'
         59        SEND_VAR_EX                                              !1
         60        DO_FCALL                                      0  $32     
         61        ASSIGN                                                   !2, $32
   79    62        BOOL_NOT                                         ~34     !2
         63      > JMPZ                                                     ~34, ->68
         64    >   NEW                                              $35     'Exception'
         65        SEND_VAL_EX                                              'Sorry%2C+user+not+found'
         66        DO_FCALL                                      0          
         67      > THROW                                         0          $35
   81    68    >   INIT_STATIC_METHOD_CALL                                  'Session', 'getLoggedInUser'
         69        DO_FCALL                                      0  $37     
         70        ASSIGN                                                   !3, $37
   83    71        INIT_METHOD_CALL                                         !3, 'follow'
         72        SEND_VAR_EX                                              !2
         73        DO_FCALL                                      0          
         74      > JMP                                                      ->80
   84    75  E > > CATCH                                       last         'Exception'
   85    76    >   NEW                                              $40     'Exception'
         77        SEND_VAL_EX                                              'Unable+to+follow+at+this+time'
         78        DO_FCALL                                      0          
         79      > THROW                                         0          $40
   89    80    >   INIT_FCALL                                               'mail'
   90    81        FETCH_OBJ_R                                      ~42     !2, 'email'
         82        SEND_VAL                                                 ~42
   91    83        SEND_VAL                                                 'You+have+a+new+follower%21'
   92    84        FETCH_OBJ_R                                      ~43     !3, 'username'
         85        NOP                                                      
         86        FAST_CONCAT                                      ~44     ~43, '+is+now+following+you.'
         87        SEND_VAL                                                 ~44
   93    88        SEND_VAL                                                 'From%3A+notifications%40awesome-social-network.com'
         89        DO_ICALL                                                 
   97    90        INIT_STATIC_METHOD_CALL                                  'Db', 'updateActivityFeed'
   98    91        INIT_ARRAY                                       ~46     'follow', 'action'
   99    92        FETCH_OBJ_R                                      ~47     !3, 'id'
         93        ADD_ARRAY_ELEMENT                                ~46     ~47, 'from'
  100    94        FETCH_OBJ_R                                      ~48     !2, 'id'
         95        ADD_ARRAY_ELEMENT                                ~46     ~48, 'to'
  101    96        INIT_FCALL                                               'time'
         97        DO_ICALL                                         $49     
         98        ADD_ARRAY_ELEMENT                                ~46     $49, 'timestamp'
         99        SEND_VAL_EX                                              ~46
        100        DO_FCALL                                      0          
  104   101        ECHO                                                     'Followed%21+%3Ca+href%3D%22%2F%22%3EReturn+to+home%3C%2Fa%3E'
  107   102    > > 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/BhAOP
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/BhAOP
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:
288.76 ms | 1419 KiB | 32 Q