|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74349 cannot use include return string in OR condition
Submitted: 2017-03-31 12:24 UTC Modified: 2017-03-31 12:27 UTC
From: liviu dot gelea at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 7.1.3 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: liviu dot gelea at gmail dot com
New email:
PHP Version: OS:


 [2017-03-31 12:24 UTC] liviu dot gelea at gmail dot com
When "returning" a string from a file, the result behaves differently if used in a condition containing the  || operator

setup an "environment.php" file that contains:

return "production";

then run the script attached:

Test script:

// determine application environment
$environmentFile = 'environment.php';
if (!file_exists($environmentFile)) {
    $environment = 'development';
} elseif ($environment = include $environmentFile) {
    // do nothing
} else {
    $environment = 'development';

echo $environment . " ";

if (!file_exists($environmentFile) || ($environment = include $environmentFile)) {
    $environment = 'development';

echo $environment;

Expected result:
the script should echo the string
"production production"

Actual result:
"production development"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-31 12:27 UTC]
-Status: Open +Status: Not a bug
 [2017-03-31 12:27 UTC]
>|| ($environment = include $environmentFile)
Your logic is backwards.
 [2017-03-31 12:33 UTC]
Your logic should be:

if (!file_exists($environmentFile) || !($environment = include $environmentFile))
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 11:01:23 2021 UTC