title: PHP return an pagination object and displaying the links when called
body: <p>I have this pagination class which I converted from a normal procedural function to a class since I started learning OOP.  In the old procedural way, the function worked fine but I can't get this new class version to display on the screen</p>
  
  <pre><code>class Pagination {
      public function __construct() {
      }
  
      /**
       * This function is called whenever the there are several records to be displayed in the table
       * This saves the page extending further down the page creating a long list of results
       * when all the results can be spread across multiple pages
       */
      public function pagination_one($total_pages, $page, $webpage) { 
  
          // Maximum number of links per page.  If exceeded, google style pagination is generated
          $max_links = 6; 
          $h=1; 
          if($page&gt;$max_links) { 
  
              $h=(($h+$page)-$max_links); 
          } 
          if($page&gt;=1) {
              $max_links = $max_links+($page-1); 
          } 
          if($max_links&gt;$total_pages) {
              $max_links=$total_pages+1; 
          } 
          echo '&lt;div class="page_numbers"&gt; 
            &lt;ul&gt;'; 
  
          if($page&gt;"1") { 
               echo '&lt;li class="current"&gt;&lt;a href="/'.$webpage.'/1"&gt;First&lt;/a&gt;&lt;/li&gt; 
                &lt;li class="current"&gt;&lt;a href="/'.$webpage.'/'.($page-1).'"&gt;Prev&lt;/a&gt;&lt;/li&gt; '; 
          } 
  
          if($total_pages!=1) {
                    for ($i=$h;$i&lt;$max_links;$i++) { 
                  if($i==$page) { 
                      echo '&lt;li&gt;&lt;a class="current"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;'; 
                  } 
                  else 
                              { 
                      echo '&lt;li&gt;&lt;a href="/'.$webpage.'/'.$i.'"&gt;'.$i.'&lt;/a&gt; &lt;/li&gt;'; 
                  } 
              } 
          } 
  
          if(($page &gt;="1")&amp;&amp;($page!=$total_pages)) {
  
      echo '&lt;li class="current"&gt;&lt;a href="/'.$webpage.'/'.($page+1).'"&gt;Next&lt;/a&gt;&lt;/li&gt; 
            &lt;li class="current"&gt;&lt;a href="/'.$webpage.'/'.$total_pages.'"&gt;Last&lt;/a&gt;&lt;/li&gt;'; 
          } 
          echo '&lt;/ul&gt; &lt;/div&gt;'; 
      }
  </code></pre>
  
  <p>and elsewhere in another class I want to create a new instance of that class and pass the method in the return along with some parameters</p>
  
  <pre><code>public function paging() {
      if($this-&gt;getcount != 0) {
            $this-&gt;paging = new Pagination();
            return $this-&gt;paging-&gt;pagination_one($this-&gt;total_pages, $this-&gt;page, 'news');
          }
      }
  </code></pre>
  
  <p>When I try I var_dump() it comes up as NULL where I expect to see some pagination on the screen.</p>
  
  <p>What have i got to change to be able to display the pagination?  Do I have to created some variables in the Pagination class for $total_pages, $page and $webpage and initialise them in the constructor and remove them from the pagination_one method?</p>