function php with parameter 0

Posted by Arnaud Ncy on Stack Overflow See other posts from Stack Overflow or by Arnaud Ncy
Published on 2012-12-15T11:01:20Z Indexed on 2012/12/15 11:03 UTC
Read the original article Hit count: 272

I have a function like this

public function get_page($position) {

    switch ($position) {
        case "current":
            echo "current";
            return $this->current_page;
            break;
        case "first":
            echo "first";
            return $this->current_page >= 3 ? 1 : false;
            break;
        case "last":
            echo "last";
            return $this->current_page <= $this->total_pages() - 2 ? ceil($this->count / $this->nb_items_to_show) : false;
            break;
        case "previous":
            echo "previous";
            return $this->current_page - 1 >= 1 ? $this->current_page - 1 : false;
            break;
        case "next":
            echo "next";
            return $this->current_page + 1 <= $this->total_pages() ? $this->current_page + 1 : false;
            break;
        case is_int($position):
            echo "int";
            if ($position >= 1 && $position <= $this->total_pages()) {
                return $position;
            } else {
                return false;
            }
            break;
        default:
            echo "default";
            return false;
            break;
    }
}

When I call the function, it works for every parameters except 0 and goes in "current" case in the switch.

$paginator->get_page(0);

If I call the function with quotes "0", it works. But the function could be called like this

$paginator->get_page($paginator->get_page("current") - 2);

How can I call the function with parameter 0 ?

© Stack Overflow or respective owner

Related posts about php

Related posts about function