php.net |  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
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: 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
Description:
------------
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:

<?php 
return "production";

then run the script attached:

Test script:
---------------
<?php

// 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"

Patches

Pull Requests

History

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

if (!file_exists($environmentFile) || !($environment = include $environmentFile))
                                      ^
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 17:01:33 2025 UTC