TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Valid.php range method error? Or just my misunderstanding?
  • I was adding some validation rules and noticed one strange thing: if I validate some number, let us say 16 (age), and as params for range validation give 16 and 99, so this validation will not pass. I took a look at the function in Valid.php class and got this:

    /**
     * Tests if a number is within a range.
     *
     * @param   string  $number number to check
     * @param   integer $min    minimum value
     * @param   integer $max    maximum value
     * @param   integer $step   increment size
     * @return  boolean
     */
    public static function range($number, $min, $max, $step = NULL)
    {
        if ($number <= $min OR $number >= $max)
        {
            // Number is outside of range
            return FALSE;
        } ...
    

    Maybe, I'm mistaken, but if you check some range, it should include min and max values you've passed, not exclude. And in our case here $min and $max will not be logically real min and max values (as its written in param description above), cause they are not included into the array.

    E.g. php range() function works not like this and has different logic and includes its min and max params into generated array of elements, and I consider this to be the right way.

    Am I not right?

  • Ooops. Thanx, I should update to 3.3.1 :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion