php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74732 Boolean and int values are not implicitly cast during comparison
Submitted: 2017-06-09 18:56 UTC Modified: 2017-07-19 09:15 UTC
From: smorozov at sugarcrm dot com Assigned:
Status: Open Package: ibm_db2 (PECL)
PHP Version: 7.1.6 OS: Ubuntu 16.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-06-09 18:56 UTC] smorozov at sugarcrm dot com
Description:
------------
In PHP 5.6, if a boolean value is compared with an int, it's cast to int, so true == 1 and false == 0. In PHP 7.0 and 7.1, the comparison true == 1 returns false.

The script below works as expected on PHP 5.6 but doesn't on PHP 7.

Unlike https://bugs.php.net/bug.php?id=74703, this behavior doesn't depend on whether Opcache is enabled or not.

Test script:
---------------
$dsn = 'HOSTNAME=localhost;UID=db2inst1;PWD=Passw0rd;DATABASE=test';
$conn = db2_connect($dsn, null, null);

if (!$conn) {
    echo db2_conn_errormsg(), PHP_EOL;
    exit(1);
}

$stmt = db2_prepare($conn, 'SELECT 1 FROM SYSIBM.SYSDUMMY1 WHERE 1 = ?');

db2_execute($stmt, [true]);
var_dump(db2_fetch_array($stmt));

db2_execute($stmt, [1]);
var_dump(db2_fetch_array($stmt));

Expected result:
----------------
array(1) {
  [0]=>
  int(1)
}
array(1) {
  [0]=>
  int(1)
}


Actual result:
--------------
bool(false)
array(1) {
  [0]=>
  int(1)
}


Patches

boolean_path (last revision 2017-07-17 08:39 UTC) by vnkbabu@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-13 11:15 UTC] vnkbabu@php.net
-Status: Open +Status: Assigned
 [2017-07-13 11:15 UTC] vnkbabu@php.net
Our developer Abhinav Radke from IBM is working on this defect. HE is able to reproduce the issue, he is reaching out to the zend guys to fix the issue. Will update once he has the solution for this issue.
 [2017-07-17 08:39 UTC] vnkbabu@php.net
The following patch has been added/updated:

Patch Name: boolean_path
Revision:   1500280746
URL:        https://bugs.php.net/patch-display.php?bug=74732&patch=boolean_path&revision=1500280746
 [2017-07-17 08:40 UTC] vnkbabu@php.net
Hi,
  Our developer has fixed the issue. Please use the below patch to fix the problem.
https://bugs.php.net/patch-display.php?bug=74732&patch=boolean_path&revision=1500280746
 [2017-07-19 09:15 UTC] smorozov at sugarcrm dot com
Thank you! It works with the patch.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC