3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Pagination { public $current_page; public $per_page; public $total_count; public $pages_articles; public function __construct($page=1, $per_page=20, $total_count=0) { $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; $this->pages_articles=array( '<div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div>', '<div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/1lBZQ1B.png"></div>', '<div class="article-loop"><img src="https://i.imgur.com/Y5Ld4Qfh.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/8HumESY.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/CqCZBvk.png"></div>', '<div class="article-loop"><img src="http://i.imgur.com/wQVPRVp.png"></div>'); } public function offset() { return ($this->current_page - 1) * $this->per_page; } public function total_pages() { //$this->total_count=sizeof($this->pages_articles); return ceil($this->total_count/$this->per_page); } public function previous_page() { return $this->current_page - 1; } public function next_page() { return $this->current_page + 1; } public function has_previous_page() { return $this->previous_page() >= 1 ? true : false; } public function has_next_page() { return $this->next_page() <= $this->total_pages() ? true : false; } } $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 3; $total_count=8; $pagination = new Pagination($page, $per_page, $total_count); ?> <html> <body> <div> <?php $i = $pagination->offset() ; $limit = $pagination->per_page; while($i<$pagination->total_count && $limit>0) { echo $pagination->pages_articles[$i]."<br>"; $i++; $limit--; } ?> </div> <ul> <?php if($pagination->has_previous_page()) { echo '<li style="display:inline"><a href="index.php?page='.$pagination->previous_page().'">&laquo;</a></li>'; } else { echo '<li style="display:inline" class="disabled"><a href="#">&laquo;</a></li>'; } for($i=1; $i<=$pagination->total_pages(); $i++) { echo '<a href="index.php?page='.$i.'"><li style="display:inline; margin-left:5px; margin-right:5px">'.$i.'</li></a>'; } if($pagination->has_next_page()) { echo '<li style="display:inline"><a href="index.php?page='.$pagination->next_page().'">&raquo;</a></li>'; } else { echo '<li style="display:inline" class="disabled"><a href="#">&raquo;</a></li>'; } ?> </ul> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 26
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 51
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 70
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 51
Branch analysis from position: 61
Branch analysis from position: 51
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 37
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
filename:       /in/i4GZQ
function name:  (null)
number of ops:  73
compiled vars:  !0 = $page, !1 = $per_page, !2 = $total_count, !3 = $pagination, !4 = $i, !5 = $limit
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   FETCH_IS                                             ~6      '_GET'
          1        ISSET_ISEMPTY_DIM_OBJ                             1  ~7      ~6, 'page'
          2        BOOL_NOT                                             ~8      ~7
          3      > JMPZ                                                         ~8, ->9
          4    >   FETCH_R                          global              ~9      '_GET'
          5        FETCH_DIM_R                                          ~10     ~9, 'page'
          6        CAST                                              4  ~11     ~10
          7        QM_ASSIGN                                            ~12     ~11
          8      > JMP                                                          ->10
          9    >   QM_ASSIGN                                            ~12     1
         10    >   ASSIGN                                                       !0, ~12
   44    11        ASSIGN                                                       !1, 3
   45    12        ASSIGN                                                       !2, 8
   46    13        NEW                                                  $16     'Pagination'
         14        SEND_VAR_EX                                                  !0
         15        SEND_VAR_EX                                                  !1
         16        SEND_VAR_EX                                                  !2
         17        DO_FCALL                                          0          
         18        ASSIGN                                                       !3, $16
   48    19        ECHO                                                         '%0A++%3Chtml%3E%0A++%3Cbody%3E%0A++%3Cdiv%3E%0A'
   53    20        INIT_METHOD_CALL                                             !3, 'offset'
         21        DO_FCALL                                          0  $19     
         22        ASSIGN                                                       !4, $19
   54    23        FETCH_OBJ_R                                          ~21     !3, 'per_page'
         24        ASSIGN                                                       !5, ~21
   55    25      > JMP                                                          ->32
   56    26    >   FETCH_OBJ_R                                          ~23     !3, 'pages_articles'
         27        FETCH_DIM_R                                          ~24     ~23, !4
         28        CONCAT                                               ~25     ~24, '%3Cbr%3E'
         29        ECHO                                                         ~25
   57    30        PRE_INC                                                      !4
   58    31        PRE_DEC                                                      !5
   55    32    >   FETCH_OBJ_R                                          ~28     !3, 'total_count'
         33        IS_SMALLER                                           ~29     !4, ~28
         34      > JMPZ_EX                                              ~29     ~29, ->37
         35    >   IS_SMALLER                                           ~30     0, !5
         36        BOOL                                                 ~29     ~30
         37    > > JMPNZ                                                        ~29, ->26
   61    38    >   ECHO                                                         '++%3C%2Fdiv%3E%0A++%3Cul%3E%0A++++++'
   64    39        INIT_METHOD_CALL                                             !3, 'has_previous_page'
         40        DO_FCALL                                          0  $31     
         41      > JMPZ                                                         $31, ->48
   65    42    >   INIT_METHOD_CALL                                             !3, 'previous_page'
         43        DO_FCALL                                          0  $32     
         44        CONCAT                                               ~33     '%3Cli+style%3D%22display%3Ainline%22%3E%3Ca++href%3D%22index.php%3Fpage%3D', $32
         45        CONCAT                                               ~34     ~33, '%22%3E%26laquo%3B%3C%2Fa%3E%3C%2Fli%3E'
         46        ECHO                                                         ~34
   64    47      > JMP                                                          ->49
   67    48    >   ECHO                                                         '%3Cli+style%3D%22display%3Ainline%22+class%3D%22disabled%22%3E%3Ca+href%3D%22%23%22%3E%26laquo%3B%3C%2Fa%3E%3C%2Fli%3E'
   69    49    >   ASSIGN                                                       !4, 1
         50      > JMP                                                          ->57
   70    51    >   CONCAT                                               ~36     '%3Ca+href%3D%22index.php%3Fpage%3D', !4
         52        CONCAT                                               ~37     ~36, '%22%3E%3Cli+style%3D%22display%3Ainline%3B+margin-left%3A5px%3B+margin-right%3A5px%22%3E'
         53        CONCAT                                               ~38     ~37, !4
         54        CONCAT                                               ~39     ~38, '%3C%2Fli%3E%3C%2Fa%3E'
         55        ECHO                                                         ~39
   69    56        PRE_INC                                                      !4
         57    >   INIT_METHOD_CALL                                             !3, 'total_pages'
         58        DO_FCALL                                          0  $41     
         59        IS_SMALLER_OR_EQUAL                                          !4, $41
         60      > JMPNZ                                                        ~42, ->51
   72    61    >   INIT_METHOD_CALL                                             !3, 'has_next_page'
         62        DO_FCALL                                          0  $43     
         63      > JMPZ                                                         $43, ->70
   73    64    >   INIT_METHOD_CALL                                             !3, 'next_page'
         65        DO_FCALL                                          0  $44     
         66        CONCAT                                               ~45     '%3Cli+style%3D%22display%3Ainline%22%3E%3Ca+href%3D%22index.php%3Fpage%3D', $44
         67        CONCAT                                               ~46     ~45, '%22%3E%26raquo%3B%3C%2Fa%3E%3C%2Fli%3E'
         68        ECHO                                                         ~46
   72    69      > JMP                                                          ->71
   75    70    >   ECHO                                                         '%3Cli+style%3D%22display%3Ainline%22+class%3D%22disabled%22%3E%3Ca+href%3D%22%23%22%3E%26raquo%3B%3C%2Fa%3E%3C%2Fli%3E'
   78    71    >   ECHO                                                         '++%3C%2Ful%3E%0A++%3C%2Fbody%3E%0A++%3C%2Fhtml%3E'
   80    72      > RETURN                                                       1

Class Pagination:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i4GZQ
function name:  __construct
number of ops:  15
compiled vars:  !0 = $page, !1 = $per_page, !2 = $total_count
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                            !0      1
          1        RECV_INIT                                            !1      20
          2        RECV_INIT                                            !2      0
    9     3        CAST                                              4  ~4      !0
          4        ASSIGN_OBJ                                                   'current_page'
          5        OP_DATA                                                      ~4
   10     6        CAST                                              4  ~6      !1
          7        ASSIGN_OBJ                                                   'per_page'
          8        OP_DATA                                                      ~6
   11     9        CAST                                              4  ~8      !2
         10        ASSIGN_OBJ                                                   'total_count'
         11        OP_DATA                                                      ~8
   12    12        ASSIGN_OBJ                                                   'pages_articles'
   13    13        OP_DATA                                                      <array>
   21    14      > RETURN                                                       null

End of function __construct

Function offset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i4GZQ
function name:  offset
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   FETCH_OBJ_R                                          ~0      'current_page'
          1        SUB                                                  ~1      ~0, 1
          2        FETCH_OBJ_R                                          ~2      'per_page'
          3        MUL                                                  ~3      ~1, ~2
          4      > RETURN                                                       ~3
   25     5*     > RETURN                                                       null

End of function offset

Function total_pages:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i4GZQ
function name:  total_pages
number of ops:  8
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                                   'ceil'
          1        FETCH_OBJ_R                                          ~0      'total_count'
          2        FETCH_OBJ_R                                          ~1      'per_page'
          3        DIV                                                  ~2      ~0, ~1
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6      > RETURN                                                       $3
   29     7*     > RETURN                                                       null

End of function total_pages

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

End of function previous_page

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

End of function next_page

Function has_previous_page:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i4GZQ
function name:  has_previous_page
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   INIT_METHOD_CALL                                             'previous_page'
          1        DO_FCALL                                          0  $0      
          2        IS_SMALLER_OR_EQUAL                                          1, $0
          3      > JMPZ                                                         ~1, ->6
          4    >   QM_ASSIGN                                            ~2      <true>
          5      > JMP                                                          ->7
          6    >   QM_ASSIGN                                            ~2      <false>
          7    > > RETURN                                                       ~2
   38     8*     > RETURN                                                       null

End of function has_previous_page

Function has_next_page:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i4GZQ
function name:  has_next_page
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   INIT_METHOD_CALL                                             'next_page'
          1        DO_FCALL                                          0  $0      
          2        INIT_METHOD_CALL                                             'total_pages'
          3        DO_FCALL                                          0  $1      
          4        IS_SMALLER_OR_EQUAL                                          $0, $1
          5      > JMPZ                                                         ~2, ->8
          6    >   QM_ASSIGN                                            ~3      <true>
          7      > JMP                                                          ->9
          8    >   QM_ASSIGN                                            ~3      <false>
          9    > > RETURN                                                       ~3
   41    10*     > RETURN                                                       null

End of function has_next_page

End of class Pagination.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.12 ms | 2851 KiB | 14 Q