我想寫一個php簡單的分頁類。這裏是我的代碼:無法回顯php類變量
<?php
class Pagination {
public $rowsPerPage;
public $currentPage;
public $totalPages;
public $totalRows;
public $firstElement;
public $lastElement;
public function paginate()
{
if(isset($_GET['page'])){
$this->currentPage = $_GET['page'];
}
$this->totalPages = $this->totalRows/$this->rowsPerPage ;
return $this->totalPages;
$this->firstElement = $this->currentPage-1)*$this->rowsPerPage+1;
return $this->firstElement;
}
}
$totalRecords = 55;
$paginator = new Pagination();
$paginator->totalRows = $totalRecords;
$paginator->rowsPerPage = 5;
$paginator->paginate();
echo $paginator->totalPages;
echo $paginator->firstElement;
?>
我可以回顯$ paginator-> totalPages;但不是$ paginator-> firstElement。 我做錯了什麼? 謝謝
我還_construct功能 公共函數_construct(){ \t \t \t $這 - > rowsPerPage = 5; $ this-> currentPage = 1; $ this-> totalPages = 0; \t \t \t $ this-> totalRows = 40; \t \t \t $ this-> firstElement = 0; \t \t \t $ this-> lastElement = 0; \t \t \t \t} – user2359958
有超過一療法錯誤syntatic在$這個 - > firstElement你有一個右括號,但不是開放。 –
打開[錯誤報告](http://php.net/error+reporting)。 –