Edit report at https://bugs.php.net/bug.php?id=74349&edit=1
ID: 74349
Updated by: [email protected]
Reported by: liviu dot gelea at gmail dot com
Summary: cannot use include return string in OR condition
-Status: Open
+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:
>|| ($environment = include $environmentFile)
Your logic is backwards.
Previous Comments:
------------------------------------------------------------------------
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.