php.net |  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: -
Votes:2
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:
Status: Open Package: PDO MySQL
PHP Version: 5.6.11 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-07-24 16:56 UTC] stanimir at datacentrix dot org
Description:
------------
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

<?php

$chr = chr(0x00);

var_dump((bool)$chr); // bool(true)
var_dump(strlen($chr)); // int(1)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 04:01:26 2019 UTC