Part of the EllisLab Network

Bug Report

$this -> session -> userdata() return wrong result

Date: 06/15/2009 Severity: Trivial
Status: Not a Bug Reporter: username007
Version: 1.7.1
Keywords: Libraries, Session Class

Description

$this -> session -> userdata return wrong result when the session value is set to 0

PS: please excuse my poor english

Code Sample

I tried to use something like this:

if (
$this -> session -> userdata('filter_status')) {
   $this
-> db -> where('enabled', $this -> session -> userdata('filter_status'), false);
}

Expected Result

$this -> session -> userdata(‘key’) should be 0, as an integer

Actual Result

$this -> session -> userdata(‘key’) return 0 as FALSE

Comment on Bug Report

Page 1 of 1 pages
Posted by: Spol on 18 September 2009 8:33am
no avatar

This isn’t a bug, it’s expected PHP behaviour. Integer 0 evaluates to false when implicitly cast to boolean. To check for true boolean false use the !== operator.

e.g.

if ($this->session->userdata(‘filter_status’) !== false) {

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?