0, 'table'=>0); public function __construct($method, $count, $page, $items=null) { if (method_exists(__CLASS__, 'method_' . $method)) { $this->method = 'method_' . $method; } else { trigger_error('Nonexistent method', E_USER_ERROR); } if (is_int($count) and 0 < $count) { $this->count = $count; } else { trigger_error('Value must be integer', E_USER_ERROR); } if (is_int($page) and 0 < $page) { $this->tmp_page = $page; } if (is_int($items)) { if (0 < $items) $this->items = $items; else $this->items = $this->count; } else { $this->items = self::$items; } } private function countPages() { if (null === $this->pages) { $this->pages = $this->count / $this->items; } return $this->pages; } public function getPages() { return self::countPages(); } private function setPage() { if (null === $this->page) { $this->page = min($this->tmp_page, self::countPages()); } return $this->page; } public function getPage() { return self::setPage(); } private function setStart() { if (null === $this->start) { $this->start = (self::setPage() - 1) * $this->items; } return $this->start; } public function getStart() { return self::setStart(); } private function method_array() { return min((self::setStart() + $this->items), $this->count); } private function method_table() { return $this->items; } public function getStop() { return call_user_method($this->method, $this); } public function prevPage() { if (null === $this->page) { self::setPage(); } return 1 < $this->page ? $this->page - 1 : $this->page; } public function nextPage() { if (null === $this->pages) { self::countPages(); } if (null === $this->page) { self::setPage(); } return $this->pages > $this->page ? $this->page + 1 : $this->page; } } /**/ $pg = new pageMan('array', 1000, 3); echo $pg->getStop(); echo '
'; echo $pg->getStart(); echo '
'; echo $pg->getPages(); echo '
'; echo $pg->getPage(); echo '
'; echo $pg->prevPage(); echo '
'; echo $pg->nextPage(); echo '
'; ?>