|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 13 13:00:01 2025 UTC |
Your logic should be: if (!file_exists($environmentFile) || !($environment = include $environmentFile)) ^