| Newsgroups |
php.bugs |
| Message-ID |
<[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=74349&edit=1
ID: 74349
Comment by: [email protected]
Reported by: liviu dot gelea at gmail dot com
Summary: cannot use include return string in OR condition
Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: Windows 10
PHP Version: 7.1.3
Block user comment: N
Private report: N
New Comment:
Your logic should be:
if (!file_exists($environmentFile) || !($environment = include $environmentFile))
^
Previous Comments:
------------------------------------------------------------------------
[2017-03-31 12:27:15] [email protected]
>|| ($environment = include $environmentFile)
Your logic is backwards.
------------------------------------------------------------------------
[2017-03-31 12:24:42] 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"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74349&edit=1