|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70132 bit(1) always seen as true
Submitted: 2015-07-24 16:56 UTC Modified: 2021-03-02 13:35 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: stanimir at datacentrix dot org Assigned: cmb (profile)
Status: Closed Package: PDO MySQL
PHP Version: 5.6.11 OS: linux
Private report: No CVE-ID: None
 [2015-07-24 16:56 UTC] stanimir at datacentrix dot org
Using MySQL 5.5.44, BIT(1) column returns either 0x00 or 0x01,
both are considered as true by the language.

Test script:
var_dump((bool) chr(0x00));

Expected result:
boolean false

Actual result:
boolean true


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-25 21:45 UTC] fontanalorenz at gmail dot com
AFAIK the expected result is true because when 0x00 is converted by chr gives you a one char string so when you cast to bool it returns true;

To verify that you can just do


$chr = chr(0x00);

var_dump((bool)$chr); // bool(true)
var_dump(strlen($chr)); // int(1)
 [2021-03-02 13:35 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-02 13:35 UTC]
Indeed, casting a string with a NUL byte to bool is supposed to
return true.  No issue here.

Anyhow, it appears this issue has been fixed in the meantime. With
emulated prepares, I get `string(1) "0"` and `string(1) "1"`,
respectively, and without emulated prepares I get int(0)/int(1).
So casting to bool yields the desired result.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 25 04:03:34 2021 UTC