php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69825 Short-circuiting failure
Submitted: 2015-06-13 23:22 UTC Modified: 2015-06-14 00:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: michael dot babker at gmail dot com Assigned: bwoebi (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 7.0Git-2015-06-13 (Git) OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael dot babker at gmail dot com
New email:
PHP Version: OS:

 

 [2015-06-13 23:22 UTC] michael dot babker at gmail dot com
Description:
------------
Through a change made between June 09 and June 13, it appears a B/C breaking change in comparison syntax was made.  On PHP 7 builds from June 09 and earlier, the following if statement correctly evaluated:

// $options['driver'] is set to 'sqlite' in the test environment
if ($options['driver'] === 'mysql' && PHP_MAJOR_VERSION >= 7)

As of today, if either condition in this statement evaluates to true it is being interpreted as true and the code inside the conditional being executed.

Test script:
---------------
The snippet above comes from Joomla's 3.5 development branch, specifically the JDatabaseDriver::getInstance() method (https://github.com/joomla/joomla-cms/blob/3.5-dev/libraries/joomla/database/driver.php#L251).  From a Travis-CI build using PHP 7 built on May 25, there is no issue with this method (see https://travis-ci.org/joomla/joomla-cms/jobs/64725678).  With a build from today (see https://travis-ci.org/joomla/joomla-cms/jobs/66699284), there are numerous failures relating to code attempting to fetch a database driver.  Our unit tests are configured to default to a SQLite in-memory database and should not be reaching the MySQL driver.

I also tested with the following modification to getInstance on the current Git build and this change passes without an issue - https://gist.github.com/mbabker/f7f87195b31c597bd92e

Expected result:
----------------
When $options['driver'] === 'sqlite' and executed on a PHP 7 build, this if conditional should evaluate to false:

if ($options['driver'] === 'mysql' && PHP_MAJOR_VERSION >= 7) 

Actual result:
--------------
When $options['driver'] === 'sqlite' and executed on a PHP 7 build, this if conditional is evaluating to true:

if ($options['driver'] === 'mysql' && PHP_MAJOR_VERSION >= 7) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-13 23:36 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bwoebi
 [2015-06-13 23:36 UTC] bwoebi@php.net
Simpler reproduce case

var_dump(0 && 1); // bool(true)

Going to fix that...
 [2015-06-14 00:05 UTC] bwoebi@php.net
-Summary: Comparison syntax change? +Summary: Short-circuiting failure -Status: Assigned +Status: Closed
 [2015-06-14 00:05 UTC] bwoebi@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Fixed via http://git.php.net/?p=php-src.git;a=commitdiff;h=f263932f38990ebee1353c8196deff440c3397d4
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 15:01:27 2025 UTC