Welcome Guest, Not a member yet? Register   Sign In
Evaluating $this->input->post() returns false, even if the array's full
#1

[eluser]AeroCross[/eluser]
I've noticed this behavior before, and I'm starting to think that it's a Codeigniter issue.

In a for loop, I'm doing this:

Code:
echo 'New guest ' . $x . ': ';
var_dump($this->input->post('new_guest_' . $x . '_gender'));
echo '<br />';

// that outputs New guest 1: string(1) "0"

if ($this->input->post('new_guest_' . $x . '_gender') == false) {
    echo 'FALSE ';
    var_dump($this->input->post('new_guest_' . $x . '_gender'));
} else {
    echo 'TRUE ';
}
// but that outputs FALSE string(1) "0"

The source of string(1) "0" is a radio button. When accessed directly (via $this->input->post()) the value is "0", but when evaluated in an if block, it returns false.

I've been trying to see what's wrong in here for the past hour, but I can't find anything, so I'm starting to think that it's a bug.

I'm using Codeigniter 2.0 Reactor.

EDIT:

Since I can't delete the thread, I'll just point out what happens (from the PHP end). The data in the post array is a "0" (string), but when evaluated (!= false) it evaluates as false, because PHP autocasts the string 0 into bool(false) - the solution is simple, just add the extra "=" in the comparison (strict checking) and you'll be all set to go.


Messages In This Thread
Evaluating $this->input->post() returns false, even if the array's full - by El Forum - 03-10-2011, 07:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB